Kaydet (Commit) db786876 authored tarafından Martin v. Löwis's avatar Martin v. Löwis

In format(), consider sign only after grouping.

Suggested by Kevin Jacobs in bug report #129417.
üst 08dabf0a
...@@ -115,17 +115,22 @@ def format(f,val,grouping=0): ...@@ -115,17 +115,22 @@ def format(f,val,grouping=0):
"""Formats a value in the same way that the % formatting would use, """Formats a value in the same way that the % formatting would use,
but takes the current locale into account. but takes the current locale into account.
Grouping is applied if the third parameter is true.""" Grouping is applied if the third parameter is true."""
result = f % val result = f % abs(val)
fields = string.split(result, ".") fields = result.split(".")
if grouping: if grouping:
fields[0]=_group(fields[0]) fields[0]=_group(fields[0])
if len(fields)==2: if len(fields)==2:
return fields[0]+localeconv()['decimal_point']+fields[1] res = fields[0]+localeconv()['decimal_point']+fields[1]
elif len(fields)==1: elif len(fields)==1:
return fields[0] res = fields[0]
else: else:
raise Error, "Too many decimal points in result string" raise Error, "Too many decimal points in result string"
if val < 0:
return '-'+res
else:
return res
def str(val): def str(val):
"""Convert float to integer, taking the locale into account.""" """Convert float to integer, taking the locale into account."""
return format("%.12g",val) return format("%.12g",val)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment