ToMoney (open)
Creates a MONEY value from a STRING.
Syntax
LOADLIB "wh::money.whlib";
MONEY FUNCTION ToMoney(STRING value, MONEY defval)
Parameters
STRING value
The STRING value to read the MONEY value from
MONEY defval
The MONEY value to return when the string could not be converted
Return value
MONEY
The money value read from @italic value
Description
This function creates a MONEY value from a STRING. The function automatically determines the decimal separator by searching the last occurance of '.' or ','. This will then be used as the decimal point; the thousand separator is assumed to be the opposite character (i.e. '.' when the decimal separator is ',' and vice versa). When no separator is found, the decimal point is assumed to be at the end of the string and no thousand separator is defined. To avoid problems with STRING to MONEY conversions it is recommended that you replace the thousand separators by empty strings before conversions When a string cannot be converted, the default value @italic defval is returned.
Examples
// The MONEY value m will be: 1345.4
MONEY m := ToMoney("1.345,4", 0);
// The MONEY value m will be: 1234567.89
MONEY m := ToMoney("1,234,567.89", 0);
// The MONEY value m will be: 0.0 (duplicate decimal separator ',')
MONEY m := ToMoney("1,234,567", 0);
//The MONEY value m will be: 1234567
//The thousand separator is ','
MONEY m := ToMoney(Substitute("1,234,567", ",", ""), 0);
// The MONEY value m will be: 0.0 ("E" is an invalid money string)
MONEY m := ToMoney("E 17,95", 0);