Skip to content

FloatToStr ​

FloatToStr converts a Float into a String data type.

FloatToStr will not provide any formatting and the number will appear as is - which could result in lots of decimal places.

FloatToStr will use the decimal symbol as per the settings in Windows (Region) numbers.

If you need to control the format of the resulting String, use the FormatFloat function.

Declaration: Function FloatToStr( Value : Extended) : string

An example follows.

pascal
procedure OnMapEvent(var Value:Variant);
var
  MyAmount : double;
  s1 : extended;
begin
  MyAmount := 123.45;
 //Value will be equal to '123.45'
  Value := FloatToStr(MyAmount);

  s1 := '1234.56789';          //Result is 1234.56789
  LogInfo('FloatToStr(StrToFloat(' + s1 + '))->' + FloatToStr(StrToFloat(s1)));

  s1 := '12';                  //Result is 12
  LogInfo('FloatToStr(StrToFloat(' + s1 + '))->' + FloatToStr(StrToFloat(s1)));

  s1 := '0.56789';             //Result is 0.56789
  LogInfo('FloatToStr(StrToFloat(' + s1 + '))->' + FloatToStr(StrToFloat(s1)));

  s1 := '34.5';                //Result is 34.5
  LogInfo('FloatToStr(StrToFloat(' + s1 + '))->' + FloatToStr(StrToFloat(s1)));

  s1 := '234.00';              //Result is 234
  LogInfo('FloatToStr(StrToFloat(' + s1 + '))->' + FloatToStr(StrToFloat(s1)));
  LogInfo('');

end;