From Clomosy Docs

(Created page with " function StrToFloat(FloatString string):Extended; The StrToFloat function converts a number string, FloatString such as '123,456' into an Extended floating point number. It supports integer, floating point, and scientific (exponent) formats. If a decimal point appears in FloatString, then it must match the current DecimalSeparator value.<br> '''Example:'''<br> '''var''' stringValue : string; floatValue : float;<br> '''begin'''<br> // Set up the source st...")
 
No edit summary
Line 6: Line 6:


'''Example:'''<br>
'''Example:'''<br>
'''var'''
:'''Base Syntax'''
  stringValue : string;
  var
  floatValue  : float;<br>
    stringValue : string;
'''begin'''<br>
    floatValue  : float;
  // Set up the source string containing a number representation
 
  stringValue := '123,456';<br>
  begin
  // Convert it to a floating point number
 
  floatValue  := StrToFloat(stringValue);<br>
    // Set up the source string containing a number representation
  // And display the value
    stringValue := '123,456';
  ShowMessage(stringValue+' = '+FloatToStr(floatValue));<br>
 
'''end;'''
    // Convert it to a floating point number
    floatValue  := StrToFloat(stringValue);
 
    // And display the value
    ShowMessage(stringValue+' = '+FloatToStr(floatValue));
 
  end;
 
:'''TRObject Syntax'''
  var
    stringValue : string;
    floatValue  : float;
 
  {
    // Set up the source string containing a number representation
    stringValue = '123,456';
    // Convert it to a floating point number
    floatValue  = StrToFloat(stringValue);
    // And display the value
    ShowMessage(stringValue+' = '+FloatToStr(floatValue));
  }


'''Output:'''<br>
'''Output:'''<br>
  123,456 = 123,456
  123,456 = 123,456

Revision as of 13:54, 13 February 2024

function StrToFloat(FloatString string):Extended;

The StrToFloat function converts a number string, FloatString such as '123,456' into an Extended floating point number. It supports integer, floating point, and scientific (exponent) formats.

If a decimal point appears in FloatString, then it must match the current DecimalSeparator value.

Example:

Base Syntax
 var
   stringValue : string;
   floatValue  : float;
 
 begin
 
   // Set up the source string containing a number representation
   stringValue := '123,456';
 
   // Convert it to a floating point number
   floatValue  := StrToFloat(stringValue);
 
   // And display the value
   ShowMessage(stringValue+' = '+FloatToStr(floatValue));
 
 end;
TRObject Syntax
 var
   stringValue : string;
   floatValue  : float;
 
 {
   // Set up the source string containing a number representation
   stringValue = '123,456';
   // Convert it to a floating point number
   floatValue  = StrToFloat(stringValue);
   // And display the value
   ShowMessage(stringValue+' = '+FloatToStr(floatValue));
 }

Output:

123,456 = 123,456