Hey all, I just want to simply format the number of decimal places displayed when using std::cout.
If you know how please post.
Hey all, I just want to simply format the number of decimal places displayed when using std::cout.
If you know how please post.
My Favorite Programming Line:
Code:#define true ((rand() % 2) ? true : false)
look at setw and setprecision functions
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Without showpoint, setprecision sets the number of digits to display (significant figures).
With showpoint, setprecision sets the number of digits after the decimal to display.
Don't quote me on that... ...seriously
Code:#include <iostream> #include <iomanip> int main() { double money = 15.75; std::cout << std::fixed << std::setprecision (2) << money << std::endl; return 0; }