[issue1222] locale.format bug if thousand separator is space (french separator as example)
de la Musse
report at bugs.python.org
Sun Sep 30 19:17:48 CEST 2007
New submission from de la Musse:
locale.format function delete spaces in result which is a problem when
thousand separator is space (in French for example).
The problem seems in the code below (extract from locale.py):
145 while seps:
146 # If the number was formatted for a specific width, then it
147 # might have been filled with spaces to the left or right. If
148 # so, kill as much spaces as there where separators.
149 # Leading zeroes as fillers are not yet dealt with, as it is
150 # not clear how they should interact with grouping.
151 sp = result.find(" ")
152 if sp==-1:break
153 result = result[:sp]+result[sp+1:]
154 seps -= 1
>>> import locale
>>> locale.setlocale(locale.LC_NUMERIC, "fr_FR.UTF-8")
>>> locale.format("%.2f", 12345.67, True)
The correct result is '12 345,67' not '12345,67'
and if I call
>>> locale.format("%9.2f", 12345.67, True)
the result is correct
Is this behavior correct or a bug?
Tracker <report at bugs.python.org>
More information about the Python-bugs-list