# setprecision() - can I count on it rounding or not?

• 11-23-2005
major_small
setprecision() - can I count on it rounding or not?
okay, so here's the story: Back in my high school programming classes, we were told that iomanip didn't round. In my college classes, whenever we needed to round, we did it on our own.

Then somebody on these boards told me it did round, so I took a closer look at it and found out that it did round. Then in an IRC channel, somebody asked if it rounded, and somebody replied saying that it was locale specific, and not to rely on it rounding.

I tried checking the standard, and couldn't make any real sense out of what they said about it, and all of the explanations I could find about setprecision said something along the lines of "Sets the number of digits of precision".

so my question is this: Can I depend on setprecision to round numbers all the time?
• 11-23-2005
maneesh
hi ....

http://www.cplusplus.com/ref/iostrea...precision.html

cio
• 11-23-2005
major_small
Quote:

The precision determines the maximum number of digits that shall be output on insertion operations to express floating-point values, counting both the digits before and after the decimal point.
but that doesn't say anything about rouding at all... they show you in their example that it rounds, but that's the only place, and it's shady at that.

edit: the answer may lie in the definition of the word precision itself...

Quote:

Originally Posted by The American HeritageŽ Dictionary of the English Language, Fourth Edition
The number of significant digits to which a value has been reliably measured.

Quote:

Originally Posted by wiktionary
(mathematics) the number of significant digits to which a value may be measured reliably

but then I guess that kinda leaves it up to interpretation... but I'm still wondering if I'm missing anything in the standard that says it should round a number...