New submission from Francis Nimick:
Locale.format() doesn't work correctly with floating point numbers.
locale.format('%.0f', 5.5) - 6
locale.format('%.0f', 6.5) - 6
locale.format('%.0f', 7.5) - 8
locale.format('%.0f', 8.5) - 8
It seems that if the number before the decimal point is even, it
Serhiy Storchaka added the comment:
http://docs.python.org/library/functions.html#round
--
nosy: +serhiy.storchaka
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17259
___
Francis Nimick added the comment:
I did end up using round - does that mean the locale.format() behavior is
correct? It's not specified anywhere in the doc that I can find.
--
___
Python tracker rep...@bugs.python.org
R. David Murray added the comment:
Perhaps Serhiy meant to direct your attention to the note in the round docs.
Floating point is tricky.
In Python3 the round is actually half to even. I'm not sure what the
rounding algorithm is for %f, but I have a suspicion it might be half to even.
I
Eric V. Smith added the comment:
Mark is the ultimate authority here, but my recollection is (and a quick scan
of the code shows) that half to even rounding is used in all of our float to
string conversions. So that includes %f and float.__format__, among others.
--