From Clomosy Docs

No edit summary
No edit summary
Line 1: Line 1:
function StrToFloat(FloatString string):Extended;
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
function StrToFloat(const S: string):Extended;
</div>


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.
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.<br>
 
<b>Example</b><br>
<b>TRObject Syntax</b><br>
<pre>
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));
}
</pre>
<b>Base Syntax</b><br>
<pre>
var
  stringValue : string;
  floatValue  : float;
begin
   
   
If a decimal point appears in FloatString, then it must match the current DecimalSeparator value.<br>
  // Set up the source string containing a number representation
 
  stringValue := '123,456';
'''Example:'''<br>
:'''Base Syntax'''
  // Convert it to a floating point number
  var
  floatValue  := StrToFloat(stringValue);
    stringValue : string;
    floatValue  : float;
  // And display the value
 
  ShowMessage(stringValue+' = '+FloatToStr(floatValue));
  begin
 
end;
    // Set up the source string containing a number representation
</pre>
    stringValue := '123,456';
 
    // Convert it to a floating point number
    floatValue  := StrToFloat(stringValue);
 
    // And display the value
    ShowMessage(stringValue+' = '+FloatToStr(floatValue));
 
  end;


:'''TRObject Syntax'''
<b>Output:</b><br>
  var
<div class="alert alert-success" role="alert" data-bs-theme="light">
    stringValue : string;
123,456 = 123,456
    floatValue  : float;
</div>
 
  {
    // 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>
<h2> See Also </h2>
123,456 = 123,456
* [[System_Library#Type_Conversion_Functions | Type Conversion Functions]]

Revision as of 14:03, 8 October 2024

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.

Example
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));
 }

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;

Output:

See Also