System.SysUtils.TryStrToFloat

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function TryStrToFloat(const S: string; out Value: Extended): Boolean;
function TryStrToFloat(const S: string; out Value: Extended;
const AFormatSettings: TFormatSettings): Boolean;
function TryStrToFloat(const S: string; out Value: Double): Boolean;
function TryStrToFloat(const S: string; out Value: Double;
const AFormatSettings: TFormatSettings): Boolean;
function TryStrToFloat(const S: string; out Value: Single): Boolean;
function TryStrToFloat(const S: string; out Value: Single;
const AFormatSettings: TFormatSettings): Boolean;

C++

extern DELPHI_PACKAGE bool __fastcall TryStrToFloat(const System::UnicodeString S, /* out */ System::Extended &Value)/* overload */;

Properties

Type Visibility Source Unit Parent
function public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils

Description

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

Use TryStrToFloat to convert a string, 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 does not contain a valid value, TryStrToFloat returns False; it returns True otherwise.

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 AFormatSettings parameter. Before calling the thread-safe forms of TryStrToFloat, you must populate AFormatSettings with localization information. To populate AFormatSettings with a set of default locale values, call TFormatSettings.Create.

See Also