printf rounding behavior for doubles

It’s “round half to even” or “Banker’s rounding”. The last digit of the rounded representation is chosen to be even if the number is exactly half way between the two.

http://linuxgazette.net/144/misc/lg/a_question_of_rounding_in_issue_143.html:
“For the GNU C library, the rounding rule used by printf() is “bankers rounding” or “round to even”. This is more correct than some other C libraries, as the C99 specification says that conversion to decimal should use the currently selected IEEE rounding mode (default bankers rounding).”

Leave a Comment