Mercurial > babel > mirror
comparison babel/tests/numbers.py @ 580:ea413a4d754b trunk
fix format_decimal() with small Decimal values (#214, patch from George Lund)
author | fschwarz |
---|---|
date | Fri, 03 Aug 2012 08:36:21 +0000 |
parents | e77dd06c40ef |
children | 964cd2ec6f94 |
comparison
equal
deleted
inserted
replaced
579:99d51589c822 | 580:ea413a4d754b |
---|---|
138 locale='en_US') | 138 locale='en_US') |
139 self.assertEqual(fmt, '1.23E+04 m/s') | 139 self.assertEqual(fmt, '1.23E+04 m/s') |
140 # 0 (see ticket #99) | 140 # 0 (see ticket #99) |
141 fmt = numbers.format_scientific(0, '#E0', locale='en_US') | 141 fmt = numbers.format_scientific(0, '#E0', locale='en_US') |
142 self.assertEqual(fmt, '0E0') | 142 self.assertEqual(fmt, '0E0') |
143 | |
144 def test_formatting_of_very_small_decimals(self): | |
145 # previously formatting very small decimals could lead to a type error | |
146 # because the Decimal->string conversion was too simple (see #214) | |
147 number = Decimal("7E-7") | |
148 fmt = numbers.format_decimal(number, format="@@@", locale='en_US') | |
149 self.assertEqual('0.000000700', fmt) | |
143 | 150 |
144 | 151 |
145 class BankersRoundTestCase(unittest.TestCase): | 152 class BankersRoundTestCase(unittest.TestCase): |
146 def test_round_to_nearest_integer(self): | 153 def test_round_to_nearest_integer(self): |
147 self.assertEqual(1, numbers.bankersround(Decimal('0.5001'))) | 154 self.assertEqual(1, numbers.bankersround(Decimal('0.5001'))) |