Hey all, I just want to simply format the number of decimal places displayed when using std::cout.
If you know how please post.
Printable View
Hey all, I just want to simply format the number of decimal places displayed when using std::cout.
If you know how please post.
look at setw and setprecision functions
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.
Code:#include <iostream>
#include <iomanip>
int main()
{
double money = 15.75;
std::cout << std::fixed << std::setprecision (2) << money << std::endl;
return 0;
}