Refs #28280 -- Added more tests for utils.numberformat.format().
This commit is contained in:
parent
0b00a8988b
commit
b94d99af5b
|
@ -49,6 +49,12 @@ class TestNumberFormat(TestCase):
|
|||
self.assertEqual(nformat(-1 - int_max, '.'), most_max.format('-', '9'))
|
||||
self.assertEqual(nformat(-2 * int_max, '.'), most_max2.format('-'))
|
||||
|
||||
def test_float_numbers(self):
|
||||
# A float without a fractional part (3.) results in a ".0" when no
|
||||
# deimal_pos is given. Contrast that with the Decimal('3.') case in
|
||||
# test_decimal_numbers which doesn't return a fractional part.
|
||||
self.assertEqual(nformat(3., '.'), '3.0')
|
||||
|
||||
def test_decimal_numbers(self):
|
||||
self.assertEqual(nformat(Decimal('1234'), '.'), '1234')
|
||||
self.assertEqual(nformat(Decimal('1234.2'), '.'), '1234.2')
|
||||
|
@ -57,6 +63,18 @@ class TestNumberFormat(TestCase):
|
|||
self.assertEqual(nformat(Decimal('1234'), '.', grouping=2, thousand_sep=',', force_grouping=True), '12,34')
|
||||
self.assertEqual(nformat(Decimal('-1234.33'), '.', decimal_pos=1), '-1234.3')
|
||||
self.assertEqual(nformat(Decimal('0.00000001'), '.', decimal_pos=8), '0.00000001')
|
||||
self.assertEqual(nformat(Decimal('9e-19'), '.', decimal_pos=2), '0.00')
|
||||
self.assertEqual(nformat(Decimal('.00000000000099'), '.', decimal_pos=0), '0')
|
||||
self.assertEqual(
|
||||
nformat(Decimal('1e16'), '.', thousand_sep=',', grouping=3, force_grouping=True),
|
||||
'10,000,000,000,000,000'
|
||||
)
|
||||
self.assertEqual(
|
||||
nformat(Decimal('1e16'), '.', decimal_pos=2, thousand_sep=',', grouping=3, force_grouping=True),
|
||||
'10,000,000,000,000,000.00'
|
||||
)
|
||||
self.assertEqual(nformat(Decimal('3.'), '.'), '3')
|
||||
self.assertEqual(nformat(Decimal('3.0'), '.'), '3.0')
|
||||
|
||||
def test_decimal_subclass(self):
|
||||
class EuroDecimal(Decimal):
|
||||
|
|
Loading…
Reference in New Issue