1if (typeof T === 'undefined') require('../setup'); 2 3T('valueOf', function () { 4 5 function t(expected, n) { 6 T.assertEqual(expected, new Decimal(n).valueOf()); 7 } 8 9 Decimal.config({ 10 precision: 20, 11 rounding: 4, 12 toExpNeg: -9e15, 13 toExpPos: 9e15, 14 minE: -9e15, 15 maxE: 9e15 16 }); 17 18 t('0', 0); 19 t('0', '0'); 20 t('NaN', NaN); 21 t('NaN', 'NaN'); 22 t('Infinity', 1/0); 23 t('Infinity', 'Infinity'); 24 t('1', 1); 25 t('9', 9); 26 t('90', 90); 27 t('90.12', 90.12); 28 t('0.1', 0.1); 29 t('0.01', 0.01); 30 t('0.0123', 0.0123); 31 t('111111111111111111111', '111111111111111111111'); 32 t('0.00001', 0.00001); 33 34 t('-0', -0); 35 t('-0', '-0'); 36 t('-Infinity', -1/0); 37 t('-Infinity', '-Infinity'); 38 t('-1', -1); 39 t('-9', -9); 40 t('-90', -90); 41 t('-90.12', -90.12); 42 t('-0.1', -0.1); 43 t('-0.01', -0.01); 44 t('-0.0123', -0.0123); 45 t('-111111111111111111111', '-111111111111111111111'); 46 t('-0.00001', -0.00001); 47 48 // Exponential format 49 Decimal.toExpNeg = Decimal.toExpPos = 0; 50 51 t('1e-7', 0.0000001); 52 t('1.23e-7', 0.000000123); 53 t('1.2e-8', 0.000000012); 54 t('-1e-7', -0.0000001); 55 t('-1.23e-7', -0.000000123); 56 t('-1.2e-8', -0.000000012); 57 58 t('5.73447902457635174479825134e+14', '573447902457635.174479825134'); 59 t('1.07688e+1', '10.7688'); 60 t('3.171194102379077141557759899307946350455841e+27', '3171194102379077141557759899.307946350455841'); 61 t('4.924353466898191177698653319742594890634579e+37', '49243534668981911776986533197425948906.34579'); 62 t('6.85558243926569397328633907445409866949445343654692955e+18', '6855582439265693973.28633907445409866949445343654692955'); 63 t('1e+0', '1'); 64}); 65 66