FormatFloat (Convert Floating Point to String)
The FormatFloat instruction is used to convert a floating point value into a string.
Consider using Sprintf rather than FormatFloat, which provides greater flexibility and functionality.
Syntax
String = FormatFloat ( Float, FormatString )

The following program shows the use of the FormatFloat instruction. Using the software's numeric monitor, enter a value into FloatVal that should be converted into a string value.
Public FloatVal as Float
Public StringVal as String * 20
BeginProg
Scan (1,Sec,3,0)
StringVal = FormatFloat (FloatVal,"%f")
NextScan
EndProg
Remarks
The string conversion of the floating point value is formatted based on the FormatString parameter.
Parameters
Float (Floating Point)
The variable or constant that holds the floating point value to be converted.
Type: Variable or Constant
FormatString
Determines how the floating point value will be represented in the converted string The options are (m = mantissa; d = decimal; x = exponent):
Code | Description |
---|---|
%f | Decimal notation in the form of ±mmm.dddddd; precision is 6 places to the right of the decimal. |
%e (or %E) | Decimal notation in the form of ±m.dddddd e±xx; precision is 6 places to the right of the decimal. |
%g (or %G) | Mantissa and decimal are variable; trailing 0s and decimals are omitted if the input has a precision less than specified by the format string. |
%Y.Zf | Decimal notation in the form of ±m.d; field width is defined by Y and includes the sign and decimal place. Precision is defined by Z. |
%0Y.0Zf | Decimal notation in the form of ±m.d; field width is defined by Y and includes the sign and decimal place. The mantissa will be padded by leading 0s if necessary. Precision is defined by Z. The decimal will be padded with trailing 0s. |
%Ye (or %YE) | Decimal notation in the form of ±m.d e±xx; field width is defined by Y and includes the sign and decimal place. |
%Yg (or %YG) | Mantissa and decimal are variable; field width is defined by Y and includes the sign and decimal place. |
Right-click the parameter to display a list of options. The format string must be enclosed in quotes.
NOTE: Other ASCII characters can be included in the FormatString (for example, FormatFloat(Variable,"The current reading is %2.3G"
).