FormatFloat (open)
Formats a FLOAT value and returns the resulting STRING.
Syntax
LOADLIB "wh::float.whlib";
STRING FUNCTION FormatFloat(FLOAT value, INTEGER decimals)
Parameters
FLOAT value
The FLOAT value to format
INTEGER decimals
The INTEGER number of decimals (range 0 to 20)
Return value
STRING
The @italic value in string format
Description
This function creates a STRING from a FLOAT value using the given number of decimals. When the decimals parameter is less than 0 or greater than 20, a default number of 20 decimals will be shown. When the actual number of decimals is less than the requested number of decimals, zeroes will be added to return the requested number of decimals. When the actual number of decimals is greater than the requested number of decimals, the value is rounded to the requested number of decimals.
Examples
// This will print: 3.14159265
PRINT (FormatFloat(3.14159265, 8));
// This will print: 3.1415926500. Two zeroes are added to get the
// requested 10 decimals (the FLOAT value only has 8 decimals)
PRINT (FormatFloat(3.14159265, 10));
// This will print: 3.142
// The value is rounded to 3 decimals.
PRINT (FormatFloat(3.14159265, 3));