]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
In format(), consider sign only after grouping.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 21 Jan 2001 18:52:33 +0000 (18:52 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 21 Jan 2001 18:52:33 +0000 (18:52 +0000)
Suggested by Kevin Jacobs in bug report #129417.

Lib/locale.py

index 401c712104aa8de99b8ed029e20c67fe51f230a7..ac272e769efbcb18045ccc4b98a82129d94a1586 100644 (file)
@@ -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)