-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathtest_decimal.py
30 lines (21 loc) · 928 Bytes
/
test_decimal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import unittest
from decimal import *
from iptest import run_test, skipUnlessIronPython
@skipUnlessIronPython()
class DecimalTest(unittest.TestCase):
def test_explicit_from_System_Decimal(self):
import System
#int
self.assertEqual(str(Decimal(System.Decimal.Parse('45'))), '45')
#float
self.assertEqual(str(Decimal(System.Decimal.Parse('45.34'))), '45.34')
def test_formatting(self):
import System
d = System.Decimal.Parse('1.4274243253253245432543254545')
self.assertEqual('{}'.format(d), '1.4274243253253245432543254545')
self.assertEqual('{:,.2f}'.format(d), '1.43')
self.assertEqual('{:e}'.format(d), '1.427424325325e+00')
d = System.Decimal.Parse('4000000000.40000000')
self.assertEqual('{}'.format(d), '4000000000.40000000')
self.assertEqual('{:e}'.format(d), '4.000000000400e+09')
run_test(__name__)