Basic precision

I have value 1.5555 setprecision(2) then 1.56

1
2
3
4
5
6
a=1.5555;
cout << "a = " << fixed << a << setprecision(2) << endl;
b=2;
cout << "b = " << fixed << b << setprecision(2) << endl;
c=a*b; // should c=1.56*2.00 not c=1.5555*2.00
cout << fixed << c << setprecision(2);


Output :
a = 1.56
b = 2.00
c = 3.10

how to value so 3.12 is not 3.10??????????
It's not...a is still 1.5555, even though you are telling cout to only show 2 decimal places. c will equal 1.5555*2.00 rounded to 2, and there is no way to get that unless you round it yourself and use that value.
Topic archived. No new replies allowed.