summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-01-21 18:52:33 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2001-01-21 18:52:33 (GMT)
commitdb786876b6c5ab24c1cd7427fd077545dbb72fee (patch)
treecf8094e485215b928108d9f123adbedb37a11152 /Lib
parent08dabf0a7374540637ee637f1b37b8d3cf96d9bf (diff)
downloadcpython-db786876b6c5ab24c1cd7427fd077545dbb72fee.zip
cpython-db786876b6c5ab24c1cd7427fd077545dbb72fee.tar.gz
cpython-db786876b6c5ab24c1cd7427fd077545dbb72fee.tar.bz2
In format(), consider sign only after grouping.
Suggested by Kevin Jacobs in bug report #129417.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/locale.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/locale.py b/Lib/locale.py
index 401c712..ac272e7 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -115,17 +115,22 @@ def format(f,val,grouping=0):
"""Formats a value in the same way that the % formatting would use,
but takes the current locale into account.
Grouping is applied if the third parameter is true."""
- result = f % val
- fields = string.split(result, ".")
+ result = f % abs(val)
+ fields = result.split(".")
if grouping:
fields[0]=_group(fields[0])
if len(fields)==2:
- return fields[0]+localeconv()['decimal_point']+fields[1]
+ res = fields[0]+localeconv()['decimal_point']+fields[1]
elif len(fields)==1:
- return fields[0]
+ res = fields[0]
else:
raise Error, "Too many decimal points in result string"
+ if val < 0:
+ return '-'+res
+ else:
+ return res
+
def str(val):
"""Convert float to integer, taking the locale into account."""
return format("%.12g",val)