]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Remove explicit enforcement from Decimal rounding
authorIsaac Jurado <diptongo@gmail.com>
Sat, 28 May 2016 21:00:24 +0000 (23:00 +0200)
committerIsaac Jurado <diptongo@gmail.com>
Sat, 28 May 2016 21:00:24 +0000 (23:00 +0200)
Allow the rounding mode to be controlled from the currently active decimal
context.  This gives the caller the ability to control rounding mode, precision,
exponent range and all attributes that affect decimal operations.

Fixes #90

babel/_compat.py
babel/numbers.py

index 75abf9eb1b9b748dd2ad333992b9a2273f2769b0..ae290f42c90b208ddada98d230d3a8fed018f2e3 100644 (file)
@@ -61,16 +61,12 @@ number_types = integer_types + (float,)
 # Use cdecimal when available
 #
 from decimal import (Decimal as _dec,
-                     InvalidOperation as _invop,
-                     ROUND_HALF_EVEN as _RHE)
+                     InvalidOperation as _invop)
 try:
     from cdecimal import (Decimal as _cdec,
-                          InvalidOperation as _cinvop,
-                          ROUND_HALF_EVEN as _CRHE)
+                          InvalidOperation as _cinvop)
     Decimal = _cdec
     InvalidOperation = (_invop, _cinvop)
-    ROUND_HALF_EVEN = _CRHE
 except ImportError:
     Decimal = _dec
     InvalidOperation = _invop
-    ROUND_HALF_EVEN = _RHE
index 3ab366cccb14cdd8c4eec1934f80a6dd8e9926d5..67881ae56986c5321d32f760829399e37c515c5f 100644 (file)
@@ -22,7 +22,7 @@ import re
 from datetime import date as date_, datetime as datetime_
 
 from babel.core import default_locale, Locale, get_global
-from babel._compat import Decimal, InvalidOperation, ROUND_HALF_EVEN
+from babel._compat import Decimal, InvalidOperation
 
 
 LC_NUMERIC = default_locale('LC_NUMERIC')
@@ -604,7 +604,7 @@ class NumberPattern(object):
                 number += get_decimal_symbol(locale) + b
         else:  # A normal number pattern
             precision = Decimal('1.' + '1' * frac_prec[1])
-            rounded = value.quantize(precision, ROUND_HALF_EVEN)
+            rounded = value.quantize(precision)
             a, sep, b = str(abs(rounded)).partition(".")
             number = (self._format_int(a, self.int_prec[0],
                                        self.int_prec[1], locale) +
@@ -641,7 +641,7 @@ class NumberPattern(object):
     def _format_significant(self, value, minimum, maximum):
         exp = value.adjusted()
         scale = maximum - 1 - exp
-        digits = str(value.scaleb(scale).quantize(Decimal(1), ROUND_HALF_EVEN))
+        digits = str(value.scaleb(scale).quantize(Decimal(1)))
         if scale <= 0:
             result = digits + '0' * -scale
         else: