Hey all, I just want to simply format the number of decimal places displayed when using std::cout.
If you know how please post.
This is a discussion on float formatting using cout within the C++ Programming forums, part of the General Programming Boards category; Hey all, I just want to simply format the number of decimal places displayed when using std::cout. If you know ...
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
The first 90% of a project takes 90% of the time,
the last 10% takes the other 90% of the time.
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; }