#Rounding with field width

11 messages · Page 1 of 1 (latest)

uneven loom
#

With this code,

printf("%.1f\n", 3.25);
printf("%.1f\n", 3.75);

It outputs,

3.2
3.8

Why is the former rounded down and the latter rounded up?

timber stumpBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

torpid pelican
#

it's rounding to the even number

#

also you can change what gets output here with fesetround

#

(e.g. if you fesetround(FE_DOWNWARD) beforehand, it outputs 3.2 3.7)

uneven loom
#

whats this behaviour called

torpid pelican
torpid pelican
opaque hamlet