RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.TryStrToFloat Function

Converts a given string to a floating-point value with a boolean success code.

Pascal
function TryStrToFloat(const S: string; out Value: Extended): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Extended; const FormatSettings: TFormatSettings): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Double): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Double; const FormatSettings: TFormatSettings): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Single): Boolean; overload;
function TryStrToFloat(const S: string; out Value: Single; const FormatSettings: TFormatSettings): Boolean; overload;
C++
Boolean TryStrToFloat(const AnsiString S, Extended Value);
Boolean TryStrToFloat(const AnsiString S, Extended Value, const TFormatSettings FormatSettings);
Boolean TryStrToFloat(const AnsiString S, Double Value);
Boolean TryStrToFloat(const AnsiString S, Double Value, const TFormatSettings FormatSettings);
Boolean TryStrToFloat(const AnsiString S, Single Value);
Boolean TryStrToFloat(const AnsiString S, Single Value, const TFormatSettings FormatSettings);

SysUtils

Use TryStrToFloat to convert a astring, S, to a floating-point value. S must consist of an optional sign (+ or -), a string of digits with an optional decimal point, and an optional mantissa. The mantissa consists of 'E' or 'e' followed by an optional sign (+ or -) and a whole number. Leading and trailing blanks are ignored. 

The DecimalSeparator global variable defines the character that must be used as a decimal point. Thousand separators and currency symbols are not allowed in the string. If S doesn't contain a valid value, TryStrToFloat returns Default.  

TryStrToFloat places the result in Value, and returns true if the conversion was successful, false otherwise. 

The first three forms of TryStrToFloat are not thread-safe, because they use localization information contained in global variables. The second three forms of TryStrToFloat, which are thread-safe, refer to localization information contained in the FormatSettings parameter. Before calling the thread-safe forms of TryStrToFloat, you must populate FormatSettings with localization information. To populate FormatSettings with a set of default locale values, call GetLocaleFormatSettings

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!