I have a list of float
values and I want to print them with cout
with 2 decimal places.
For example:
10.900 should be prin
I had an issue for integers while wanting consistent formatting.
A rewrite for completeness:
#include
#include
int main()
{
// floating point formatting example
double d = 122.345;
std::cout << std::fixed << std::setprecision(2) << d << std::endl;
// Output: 122.34
// integer formatting example
int i = 122;
std::cout << std::fixed << std::setprecision(2) << double(i) << std::endl;
// Output: 122.00
}