help files
Z505 | PasWiki | FUQ | Search | Main Docs | API Guide



[Overview][Constants][Types][Classes][Procedures and functions][Variables] Reference for unit 'sysutils' (#rtl)

StrToFloat

Convert a string to a floating-point value.

Declaration

Source position: line 0

function StrToFloat(

  const S: String

):Extended;

function StrToFloat(

  const S: String;

  const FormatSettings: TFormatSettings

):Extended;

Description

StrToFloat converts the string S to a floating point value. S should contain a valid stroing representation of a floating point value (either in decimal or scientific notation). If the string contains a decimal value, then the decimal separator character can either be a '.' or the value of the DecimalSeparator variable.

Errors

If the string S doesn't contain a valid floating point string, then an exception will be raised.

See also

TextToFloat

  

Convert a buffer to a float value.

FloatToStr

  

Convert a float value to a string using a fixed format.

FormatFloat

  

Format a float according to a certain mask.

StrToInt

  

Convert a string to an integer value.

Example

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.

Notes

 No notes exist for this page yet. 





lufdoc, Powtils, fpc, freepascal, delphi, kylix, c/c++, mysql, cgi web framework docs, Z505