Numeric Conversion

The following functions are defined in the SysUtils unit and are much used:

CurrToStr(Value: Currency):string;

 - converts currency to string using local symbol and format.

For example: CurrToStr(currency_variable);

CurrToStringF (Value: Currency; Format: TFloatFormat; Digits:Integer): string;

 - converts currency value to string using using given format (usually ffCurrency) and digits places after the decimal place.

For example: CurrToStrF(currency_variable, ffCurrency, 2));

See FloatToStrF for more details on format.

FloatToStr(Value: Extended): string;

 - converts floating-point number to string using general format to 15 digits precision.

FloatToStrF (Value: Extended; Format: TFloatFormat; Precision, Digits: Integer): string;

 - Values for TFloatFormat are: ffGeneral, ffExponent, ffFixed, ffNumber and ffCurrency.

Precision is number of significant figures.

Uses DecimalSeparator and ThousandSeparator to display decimal places and separator symbol (eg comma).

Formats work in similar way to spreadsheet:

For example: FloatToStrF(float_variable, ffGeneral, 8, 4));

For example: FloatToStrF(float_variable, ffNumber, 10, 3));

For example: FloatToStrF(float_variable, ffCurrency, 6, 2));
 

FormatCurr(const Format: string; Value: Currency): string;

 - formats a currency value as a string, according to Format argument.

FormatFloat(const Format: string; Value: Extended): string;

 - formats floating point value as a string, according to Format argument.

IntToHex(Value: Int64; Digits: Integer): string; overload;

 - formats Int64 as a string.

IntToStr(Value: Integer; Digits: integer): string; overload;

- formats integer as a string.

StrToCurr(const S: string): Currency;

- converts string to Currency. If string invalid EConvertError exception is raised.

StrToFloat(const S: string): Extended;

  - converts string to floating point. If string invalid EConvertError exception is raised.

StrToInt64(const S: string): Int64;

 - converts string to Int64. If string invalid EConvertError exception is raised.

StrToInt(const S: string): Integer;

- converts string to integer. If string invalid EConvertError exception is raised.

StrToInt64Def(const S: string; Default: Int64): Int64;

- converts string to Int64. Leading and trailing white space ignored. If string empty or invalid the default value is returned.

StrToIntDef(const S: string; Default: Integer): Integer;

- converts string to integer. Leading and trailing white space ignored. If string empty or invalid the default value is returned.

TextToFloat(Buffer: PChar; var: Value; ValueType: TFloatValue): Boolean; - 

Back to Delphi Menu