Skip to content

Regarding rounding behavior with "printf("%.0f\n", 2.5);" in C. #5514

Discussion options

You must be logged in to vote

Hello @ArielMAJ,

It is very interesting question indeed, i've just read the ISO/IEC 9899:2011 (in open edition), namely §7.21.6.1 (p. 309) and it says about rounding, not truncating and it says nothing special about the values in the very middle of range.

From the other hand i did some investigating and searches and it looks like not all compilers follow the same rule and in real life use different strategies for the values in the very middle of range (nearest even for example)

Seeing different platforms and different versions (9.x and 8.x)of the different toolchains i would not expect the same output. Although you may play with installing the same version of gcc but i would not expect to…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by ArielMAJ
Comment options

You must be logged in to vote
1 reply
@ArielMAJ
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants