setprecision

my instructor posted on his handout

void resetFormat()
{
cout<<resetiosflags(ios::fixed|ios::showpoint);
cout<<setprecision(6);
}

I thought i would get 6 decimals like 8.378291 but instead i the screen output diplayed 5 8.37829.

i have no clue why.
any suggestions??
i believe setprecision sets the amount of numbers the variable should be converted to. this means that in this case your number will be converted to 6 numbers: 1 integer and 5 decimals.
So just make the setprecision(7) to get 6 decimals :)

Cheers!
If you always want 6 decimals after the decimal point, you should not reset fixed, but rather set it (cout << fixed;).
Otherwise, the number of decimals will vary with the number of digits before the decimal point.
Topic archived. No new replies allowed.