diff babel/numbers.py @ 557:4e561e6411ba trunk

Only use bankers round algorithm as a tie breaker if there are two nearest numbers, round as usual if there is only one nearest number (#267, patch by Martin)
author fschwarz
date Tue, 30 Aug 2011 20:53:33 +0000
parents aa53048ad7ac
children 39ff5164e8ea
line wrap: on
line diff
--- a/babel/numbers.py
+++ b/babel/numbers.py
@@ -361,6 +361,13 @@
         add = 1
     elif digits[i] == '5' and digits[i-1] in '13579':
         add = 1
+    elif digits[i] == '5':     # previous digit is even
+        # We round up unless all following digits are zero.
+        for j in xrange(i + 1, len(digits)):
+            if digits[j] != '0':
+                add = 1
+                break
+
     scale = 10**ndigits
     if isinstance(value, Decimal):
         return Decimal(int(value * scale + add)) / scale * sign
Copyright (C) 2012-2017 Edgewall Software