I have a list of float
values and I want to print them with cout
with 2 decimal places.
For example:
How can I do this?
(setprecision
doesn't seem to help in this.)
With <iomanip>
, you can use std::fixed
and std::setprecision
Here is an example
#include <iostream>
#include <iomanip>
int main()
{
double d = 122.345;
std::cout << std::fixed;
std::cout << std::setprecision(2);
std::cout << d;
}
And you will get output
122.34