| Description |
Attempts to parse the Value string into a value in the range +/-79,228,162,514,264,337,593,543,950,335, returning a Decimal object with this value.
The Style parameter determines the allowed number content. It is an enumerated type that is treated as a set of flags (it has the [Flags] attribute. This means that multiple values may be set, using logical or. The possible values are :
| AllowCurrencySymbol | Allow for ?,$ ... |
| AllowExponent | E+000 format |
| AllowThousands | For example : 1,000,000 |
| AllowDecimalPoint | For example : 123.456 |
| AllowParentheses | For example (1234) |
| AllowTrailingSign | For example : 123- |
| AllowLeadingSign | For example : -123 |
| AllowTrailingWhite | Allow trailing blanks |
| AllowLeadingWhite | Allow leading blanks |
| AllowHexSpecifier | For example : 0x2bcd |
The FormatProvider option allows for customised formatting and is beyond the scope of Delphi Basics.
|
| | Notes | Warning : An exception is thrown if the parse encounters unexpected characters.
|
| | References | NumberStyles
|
|
| Microsoft MSDN Links |
System
System.Decimal
|
|
|
| A simple example |
program Project1;
{$APPTYPE CONSOLE}
var
decStr : String;
result : Decimal;
begin
decStr := '-123.45';
result := System.Decimal.Parse(decStr);
Console.WriteLine('''' + decStr + ''' parses to {0}', result.ToString);
Console.ReadLine;
end.
| | Show full unit code | '-123.45' parses to -123.45
| | | Using NumberStyles | program Project1;
{$APPTYPE CONSOLE}
uses
System.Globalization;
var
style : NumberStyles;
decStr : String;
result : Decimal;
begin
// Allow for hex values and leading/trailing blanks
style := NumberStyles.AllowLeadingWhite or
NumberStyles.AllowTrailingWhite or
NumberStyles.AllowThousands;
decStr := ' 123,456,789 ';
result := System.Decimal.Parse(decStr, style);
Console.WriteLine('''' + decStr + ''' parses to {0}', result.ToString);
// Or more simply using one combined number style value
style := NumberStyles.HexNumber;
decStr := ' AC '; // Hex AC = 189
result := System.Decimal.Parse(decStr, style);
Console.WriteLine('''' + decStr + ''' parses to {0}', result.ToString);
Console.ReadLine;
end.
| | Show full unit code | ' 123,456,789 ' parses to 123456789
' AC ' parses to 189
|
| |
|
|
|