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

TextToFloat

Convert a buffer to a float value.

Declaration

Source position: line 0

function TextToFloat(

  Buffer: PChar;

  var Value: Extended

):Boolean;

function TextToFloat(

  Buffer: PChar;

  var Value;

  ValueType: TFloatValue

):Boolean;

Description

TextToFloatconverts the string in Bufferto a floating point value. Buffershould contain a valid stroing representation of a floating point value (either in decimal or scientific notation). If the buffer contains a decimal value, then the decimal separator character can either be a '.' or the value of the DecimalSeparatorvariable.

The function returns Trueif the conversion was successful.

Errors

If there is an invalid character in the buffer, then the function returns False

See also

StrToFloat

  

Convert a string to a floating-point value.

FloatToStr

  

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

FormatFloat

  

Format a float according to a certain mask.

Example

Program Example91;

{ This program demonstrates the TextToFloat function }
{$mode objfpc}
{$h+ }

Uses SysUtils;

Const
  NrValues = 5;
  TestStr : Array[1..NrValues] of pchar =
           ('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]);
    If TextToFloat(TestStr[i],E) then
      Writeln('Converted value : ',E)
    else
      Writeln('Unable to convert value.');
    end;
end;

Begin
  DecimalSeparator:=',';
  Testit;
  DecimalSeparator:='.';
  Testit;
End.