formating floats

Can anyone point me to aplace where i can find information about formatting floats or intergers. What i am looking for is to take a float and want to put a comma in the thousands, millions spot and maybe a $ in the front of the number to make it dollars.

example: i want 1000000 to look like this 1,000,000 or $1000.00 look like this $1,000.00

I not worried about decimal places i know how to do that. Just not sure and have looked all over this forum and site but can't find help. I may not be wording it right. The fill command doesn't seem to fill the bill unless i misunderstood how it is used. any help in point to the right direction would be greatly appreciated. Thank you in advance.
You could use locales

eg:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Comma: public numpunct<char>// own facet class
{
     protected: 
          char do_thousands_sep() const { return ','; }// use the comma
          string do_grouping() const { return "\3"; }//group 3 digits
};

int main()
{
     locale myloc(  locale(),    // C++ default locale
          new Comma);// Own numeric facet

     cout.imbue(myloc);// set locale to cout

     cout << 100000;

     return 0;
}

http://www.cplusplus.com/reference/std/locale/
Last edited on
Thank you Brazzy. sorry it took so long to thank you but i got sidetracked. Thank you again for your reply
Topic archived. No new replies allowed.