[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] |
Convert a string to a floating-point value.
Source position: sysstrh.inc line 185
function StrToFloat( |
const S: string |
):Extended; |
const S: string; |
const FormatSettings: TFormatSettings |
):Extended; |
StrToFloat converts the string S to a floating point value. S should contain a valid string representation of a floating point value (either in decimal or scientific notation). The thousandseparator character may however not be used.
Up to and including version 2.2.2 of the compiler, if the string contains a decimal value, then the decimal separator character can either be a '.' or the value of the DecimalSeparator variable.
As of version 2.3.1, the string may contain only the DecimalSeparator character. The dot ('.') can no longer be used instead of the DecimalSeparator.
If the string S doesn't contain a valid floating point string, then an exception will be raised.
|
Convert a buffer to a float value. |
|
|
Convert a float value to a string using a fixed format. |
|
|
Format a float according to a certain mask. |
|
|
Convert a string to an integer value. |
Program Example90; { This program demonstrates the StrToFloat function } {$mode objfpc} {$h+ } Uses SysUtils; Const NrValues = 5; TestStr : Array[1..NrValues] of string = ('1,1','-0,2','1,2E-4','0','1E4'); Procedure Testit; Var I : Integer; E : Extended; begin Writeln('Using DecimalSeparator : ',DecimalSeparator); For I:=1 to NrValues do begin Writeln('Converting : ',TestStr[i]); Try E:=StrToFloat(TestStr[i]); Writeln('Converted value : ',E); except On E : Exception do Writeln('Exception when converting : ',E.Message); end; end; end; Begin DecimalSeparator:=','; Testit; DecimalSeparator:='.'; Testit; End.