#include <iostream>
#include <iomanip>
int main()
{
float f = 0.115;
std::cout << f << std::endl;
std::cout << std::fixed << std::setprecision(2) << f << std::endl;
return 0;
}
The output of the above code is:
0.115
0.12
It makes sense that 0.115 is rounded to 0.12. However, when we change f to 0.225 the output is:
0.225
0.22
Why isn't this rounded to 0.23?