FormatMoney (open)
Formats a MONEY value and returns the resulting STRING.
Syntax
LOADLIB "wh::money.whlib";
STRING FUNCTION FormatMoney(MONEY value, INTEGER decimals, STRING decimalsep, STRING thousandsep, BOOLEAN round)
Parameters
MONEY value
The @italic money value to format
INTEGER decimals
The number of decimals (range 0 to 5)
STRING decimalsep
The decimal separator (e.g. ',')
STRING thousandsep
The thousand separator (e.g. '.')
BOOLEAN round
Indicates if the value needs to be rounded or expanded
Return value
STRING
The string formatted @italic value
Description
This function creates a STRING from a MONEY value using the given format parameters. The number of decimals can be 0 to 5. When the decimals parameter is less than 0 or greater than 5, all decimals will be shown. When the actual number of decimals is greater than the requested number of decimals, the value will be rounded to fit when the round parameter is TRUE. When round is FALSE, all significant decimals will be shown, with at least the given number of decimals. When decimals are rounded, the following rules apply: 5 and higher is rounded up, 4 and lower is rounded down, e.g. 0.15 rounded to 1 decimal becomes 0.2 and 0.14 becomes 0.1. decimalsep and thousandsep may be empty, in which case there will be no decimal or thousand separator.
Examples
// This will print: 10,001.3
// FormatMoney has rounded this value
PRINT (FormatMoney(10001.3454, 1, ".", ",", TRUE));
// This will print: 10.001,4
// FormatMoney has rounded this value
PRINT (FormatMoney(10001.3554, 1, ",", ".", TRUE));
// This will print: 1.3454
// No rounding, so the exact number of decimals will be printed
PRINT (FormatMoney(1.3454, 1, ".", ",", FALSE));