Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2001-05-09 18:27:09

On Wednesday, May 9, 2001, at 06:50 PM, John Max Skaller wrote:

>> Anyway, I'm hoping that standard C++ facilities (I/O streams,
>> I/O manipulators and locale facets) will be sufficient.
> They definitely aren't. They're enough for
> debugging, or printing a short 'You owe me $25.00!'.
> They may be enough for ticketing. They're completely
> useless for serious commercial reporting,
> _especially_ financial reports. These things have
> formatting rules which go well beyond the primitive
> features of IO streams: the number of options is
> quite large. for example, sometimes negative
> numbers are written with brackets:
> (234.75)

This can be handled by having a class derived from
std::moneypunct<charT> return "()" from the virtual function

> and sometimes with a trailing minus
> 234.75-

do_negative_sign() should return "-" and do_neg_format() should return a
pattern with "sign" as the last element.

> and sometimes spaces are required:
> 12 234.76

You mean as a thousands separator? Have do_thousands_sep() return ' '.

> and sometimes commas:
> 12,234.76

Have do_thousands_sep() return ','

> and sometimes a floating dollar sign:
> $12.30
> $222.70
> and sometimes a fixed position for the sign:
> $ 12.30
> $222.70

Set adjustfield to internal, set width appropriately, and put "none" in
the pattern where you need to fill up space (and set the fill character
if it isn't what you want already).

> and it goes on and on. ...<snip>...In any case, the right way to do IO
> is to do formatting
> 'in-core', and output a string. So the facilities in
> iostreams are really for debugging, and nothing more.

I disagree. The monetary formatting functionality in <locale> is fairly
thorough and complete. You haven't shown any examples here that the std
monetary facets won't handle.


Boost list run by bdawes at, gregod at, cpdaniel at, john at