Image

Imagetehkate wrote in Imagecpp 😊cheerful

Listens: Cave In--Anchor

Hello

I am looking over my midterm and I have no idea why this answer is the way it is. I have typed this into my wonderful compiler and get the same result (which is frustrating because you always hope that you can prove the profs wrong!) anyway! The question was (pretty simple):

float x=3.14159f
cout << setprecision(3) << fixed << internal << "#" << setw(6) << x << "#";

What is the output?


The answer is # 3.142#

The format, I understand. The fixed, setw, and setprecision are pretty self explanitory. I have, however, no clue why there is rounding going on. I tried to omit the "internal" (<--don't know what that means) and it still rounded it. Why is it rounded not truncated? Is this a property of the floating point numbers?

I know this is pretty simple stuff just frustrating because I don't want to get a silly quesiton like this on the final and lose points on something as simple as this.

Thanks!