RWDecimalPortable
RWDecimalPortable is a class from Essential Tools Module that is used to hold monetary values. For this job, it is more accurate than float or double. The types float and double introduce errors in monetary values because binary is not entirely accurate for fractional base 10 values. RWDecimalPortable uses the less efficient but perfectly accurate ASCII method.
When an RWDecimalPortable instance is given to the DB Interface Module to be inserted into a table, the module handles any formatting required by the server automatically. However, you do need to get localized values into instances of RWDecimalPortable.
Unfortunately, there is no constructor for RWDecimalPortable that takes an RWLocale as a parameter. When an RWDecimalPortable is initialized from a string, it always assumes that the string is formatted in the style required by the current global locale.
 
void
demoI18NDecimal()
{
// this example is supposed to be French
// these two lines make sure that's true
RWLocaleSnapshot france("fr");
const RWLocale* oldLocale = RWLocale::global(&france);
 
RWCString frenchDecimalString("123.456,78");
RWDecimalPortable x(frenchDecimalString);
 
cout << "in France: " << x << endl;
RWLocaleSnapshot USLocale("en_us");
USLocale.imbue(cout);
cout << "in the US: " << x << endl;
 
//restore previous locale
RWLocale::global(oldLocale);
}
The output for this example should be:
 
in France: 123456,78
in the US: 123456.78
By itself, class RWDecimalPortable cannot produce output with embedded thousand separators. When used in conjunction with the Currency Module, it has that capability.