DOLLAR FORMAT?

closed account (3796URfi)
How do I make a number appear in dollar format with the "$" dollar sign and with decimals?
Last edited on
If you have a compiler that supports C++11, it's as easy as put_money:

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <iomanip>
#include <locale>

int main()
{
    int number = 123; // 1 dollar and 23 cents
    std::cout.imbue(std::locale("en_US.utf8"));
    std::cout << std::showbase << std::put_money(number) << '\n';
}

demo: http://ideone.com/5YNXfw
Last edited on
Topic archived. No new replies allowed.