Tools.h++ Manual
4-10 104011 Tandem Computers Incorporated
4
The French use “,” for the decimal point, and “.” for the digit group separator,
so this might display:
1.234567e+07 987654
1.234.567,89 987.654
Numbers with digit group separators are certainly easier to read.
Currency
Currency conversions are trickier, mainly because there is no standard way to
represent monetary values in a computer. We have adopted the convention
that such values represent an integral number of the smallest unit of currency
in use. For example, in the U.S, to represent the balance “$10.00”, you might
say
double sawbuck = 1000.;
This representation has the advantages of wide range, exactness, and
portability. By wide range, we mean that it can exactly represent values from
$0.00 up to (and beyond) $10,000,000,000,000.00. This is larger than any likely
budget. By exactness, we mean that representing monetary values without
fractional parts, you can perform arithmetic on them and compare the results
for equality:
This would not be possible if the values were naively represented, as for
instance "
price = 9.99;
".
By portability, we mean simply that
double
is a standard type, unlike
common 64-bit integer or BCD representations. Of course, financial
calculations may still be performed on such other representations, but because
it is always possible to convert between them and
double
, this supports
everyone. In the future
RWLocale
may directly support some other common
representations as well.
double price = 999.; // $9.99
double penny = 1.; // $.01
assert(price + penny == sawbuck);