TITLE: formatting numbers (Newsgroups: comp.lang.c++, 11 Jan 2000) THOMAS: "Jim Thomas" > I need to know how to put the comma in 10,000. I did it in a > rather large function.I would like to find a easier way to > display $10,000.00 without having to do modulus math. This > would be greatly appreciated. KUEHL: Dietmar Kuehl I have seen several answers suggesting some kind of post processing. The "right" answer is to just install a suitable 'std::numpunct' facet and be done since the numeric formatting then inserts the thousands separators automatically. More concrete, just do this: class my_numpunct: public std::numpunct' facet with the suitable grouping. It then goes on to create a 'std::locale' object which is just the global locale object with only the 'std::numpunct' facets replaced. Finally, the newly created locale object is installed, or 'imbue()'ed in the stream 'std::cout'. By default, the global locale at the construction time of the stream is used. The locale of a stream can be replaced using the function 'imbue()' (defined in 'std::ios_base'). The global locale can be replaced using the static function 'std::locale::global()'. _______________________________________________ cpptips mailing list http://cpptips.hyperformix.com