• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1if (typeof T === 'undefined') require('../setup');
2
3T('toFixed', function () {
4
5  function t(expected, n, dp) {
6    T.assertEqual(expected, new Decimal(n).toFixed(dp));
7  }
8
9  function tx(fn, msg) {
10    T.assertException(fn, msg);
11  }
12
13  Decimal.config({
14    precision: 20,
15    rounding: 4,
16    toExpNeg: -9e15,
17    toExpPos: 9e15,
18    minE: -9e15,
19    maxE: 9e15
20  });
21
22  t('100.0', 99.9512986, 1);
23  t('10.0',  9.95036, 1);
24  t('1.0', 0.99, 1);
25  t('0.10', 0.09906, 2);
26  t('0.010', 0.0098034, 3);
27
28  t('NaN', NaN, 2);
29  t('Infinity', 1/0, 2);
30  t('-Infinity', -1/0, 2);
31
32  t('1111111111111111111111.00000000', '1111111111111111111111', 8);
33  t('0.1', 0.1, 1);
34  t('0.10', 0.1, 2);
35  t('0.100', 0.1, 3);
36  t('0.01', 0.01, 2);
37  t('0.010', 0.01, 3);
38  t('0.0100', 0.01, 4);
39  t('0.00', 0.001, 2);
40  t('0.001', 0.001, 3);
41  t('0.0010', 0.001, 4);
42  t('1.0000', 1, 4);
43  t('1.0', 1, 1);
44  t('1', 1, 0);
45  t('12', 12, 0);
46  t('1', 1.1, 0);
47  t('12', 12.1, 0);
48  t('1', 1.12, 0);
49  t('12', 12.12, 0);
50  t('0.0000006', 0.0000006, 7);
51  t('0.00000006', 0.00000006, 8);
52  t('0.000000060', 0.00000006, 9);
53  t('0.0000000600', 0.00000006, 10);
54  t('0', 0, 0);
55  t('0.0', 0, 1);
56  t('0.00', 0, 2);
57
58  t('-1111111111111111111111.00000000', '-1111111111111111111111', 8);
59  t('-0.1', -0.1, 1);
60  t('-0.10', -0.1, 2);
61  t('-0.100', -0.1, 3);
62  t('-0.01', -0.01, 2);
63  t('-0.010', -0.01, 3);
64  t('-0.0100', -0.01, 4);
65  t('-0.00', -0.001, 2);
66  t('-0.001', -0.001, 3);
67  t('-0.0010', -0.001, 4);
68  t('-1.0000', -1, 4);
69  t('-1.0', -1, 1);
70  t('-1', -1, 0);
71  t('-1', -1.1, 0);
72  t('-12', -12.1, 0);
73  t('-1', -1.12, 0);
74  t('-12', -12.12, 0);
75  t('-0.00000', -0.0000006, 5);
76  t('-0.0000006', -0.0000006, 7);
77  t('-0.00000006', -0.00000006, 8);
78  t('-0.000000060', -0.00000006, 9);
79  t('-0.0000000600', -0.00000006, 10);
80  t('0', 0, 0);
81  t('0', -0, 0);
82  t('0.0', -0, 1);
83  t('0.00', -0, 2);
84  t('0.00', '-0.0', 2);
85  t('0.00', '-0.0000', 2);
86  t('0.0000', -0, 4);
87
88  t('1000', 1000);
89  t('0.00001', 0.00001);
90  t('0.00001', 0.00001, 5);
91  t('0.00000000000000000010', '0.0000000000000000001', 20);
92  t('0.00001000000000000', 0.00001, 17);
93  t('1.00000000000000000', 1, 17);
94  t('1000000000000000128', '1000000000000000128');
95  t('100000000000000128.0', '100000000000000128', 1);
96  t('10000000000000128.00', '10000000000000128', 2);
97  t('10000000000000128.00000000000000000000', '10000000000000128', 20);
98  t('0', 0);
99  t('-42.000', -42, 3);
100  t('-1000000000000000128', '-1000000000000000128');
101  t('-0.00000000000000000010', '-0.0000000000000000001', 20);
102  t('0.12312312312312300000', '0.123123123123123', 20);
103
104  t('1', 0.5, 0);
105  t('-1', -0.5, 0);
106  t('1.3', 1.25, 1);
107  t('234.2041', 234.20405, 4);
108  t('234.2041', '234.204050000000000000000000000000006', 4);
109
110  Decimal.rounding = 0;
111
112  t('0.000001', '0.000001', 6);
113  t('6552606716539719300271040797809220.3', '6552606716539719300271040797809220.237838405', 1);
114  t('25605410.260045950231371', '25605410.260045950231370974066', 15);
115  t('-65593283.0000', '-65593283', 4);
116  t('-2238743875407788208860272230040067273281097722822075126.88000000000', '-2238743875407788208860272230040067273281097722822075126.88', 11);
117  t('-1714042659419404211.0000000', '-1714042659419404211', 7);
118  t('580861301.000', '580861301', 3);
119  t('-495746734.000', '-495746734', 3);
120  t('-909962202.00000', '-909962202', 5);
121  t('-6588.00', '-6588', 2);
122  t('-89235424125324.000000', '-89235424125324', 6);
123  t('-0.0001', '-0.0000000000177', 4);
124  t('-0.1', '-0.000000000000007', 1);
125  t('7086047552021418140460170703933026989776558656.864197000000000', '7086047552021418140460170703933026989776558656.864197', 15);
126  t('-0.0000000001', '-0.0000000000000000007707', 10);
127  t('6613833500.133407255728', '6613833500.133407255727325566781771', 12);
128  t('-0.60', '-0.6', 2);
129  t('-5800577761301861465745732694236894834.347199790459214393940', '-5800577761301861465745732694236894834.34719979045921439394', 21);
130  t('65495133621931312001260.90', '65495133621931312001260.89870016055223846451749943336585697', 2);
131  t('-0.0000001', '-0.0000000000021727264987520611266069544793244453321336', 7);
132  t('5138338134667513058267845351654.0073', '5138338134667513058267845351654.007282', 4);
133  t('-419591612781413402.1606094651083282', '-419591612781413402.16060946510832813452', 16);
134  t('-842984708.00000', '-842984708', 5);
135  t('6094679992788973717749530934167375519948195193196.00000000000', '6094679992788973717749530934167375519948195193196', 11);
136  t('3070926.00', '3070926', 2);
137  t('-0.0000000000000004274', '-0.00000000000000042733957907641417564294', 19);
138  t('-307434.0', '-307434', 1);
139  t('-7155930111672774753753.84501482871023', '-7155930111672774753753.845014828710226', 14);
140  t('-204638.0', '-204638', 1);
141  t('67354.81', '67354.801797', 2);
142  t('0.000042911675', '0.000042911674899533228107357062', 12);
143  t('-57865060735863.5903347110', '-57865060735863.590334711', 10);
144  t('-0.00889', '-0.0088857', 5);
145  t('655593535442553089245040020344044.000000000000', '655593535442553089245040020344044', 12);
146  t('-2077237944012133216588518213.9402', '-2077237944012133216588518213.9401561759783653376', 4);
147  t('3354.50', '3354.49314543', 2);
148  t('-0.00001', '-0.000000000000091204118667391473401958802734362777499449233', 5);
149  t('-2817626898661648124242602088971648489124280903.00000000000000000000000', '-2817626898661648124242602088971648489124280903', 23);
150  t('-0.1138', '-0.1137406345875745478881089475981775971743', 4);
151  t('372625.84', '372625.836933301', 2);
152  t('-0.0001', '-0.0000000000030295', 4);
153
154  Decimal.rounding = 1;
155
156  t('0.3', '0.3', 1);
157  t('-200258348374.3', '-200258348374.3595802551014614089785610548492885372322083789', 1);
158  t('-8996550690041157178188143247448286757711.5580857413', '-8996550690041157178188143247448286757711.55808574133329', 10);
159  t('-3172413669280032477.00', '-3172413669280032477', 2);
160  t('6547946357820.750067107731812021675', '6547946357820.750067107731812021675351468709784004', 21);
161  t('24188393190716631282750407915133817062572333100239.0000000000000000000', '24188393190716631282750407915133817062572333100239', 19);
162  t('539982361589798324286450574560330534901309503.82000000', '539982361589798324286450574560330534901309503.82', 8);
163  t('829898800701640360552652.0000', '829898800701640360552652', 4);
164  t('-1585782773394.4', '-1585782773394.44501382110847', 1);
165  t('-7604844176594943774211951887242195107.399', '-7604844176594943774211951887242195107.399576743428669618164', 3);
166  t('-0.00', '-0.0000000000000005153003506839', 2);
167  t('0.000', '0.00003', 3);
168  t('-5454249481540317712.560293859013731302', '-5454249481540317712.56029385901373130215526009738012974642338', 18);
169  t('15352607654972198961429295651185206861818141054385638.00000000000000000', '15352607654972198961429295651185206861818141054385638', 17);
170  t('91494535411039025233040.292', '91494535411039025233040.29224903220309368507011', 3);
171  t('2043369316.0', '2043369316', 1);
172  t('-0.0000000782350618457', '-0.0000000782350618457630647420312027682238301541350414', 19);
173  t('2122652.0', '2122652', 1);
174  t('-0.00841365', '-0.00841365099301981489219310202029642', 8);
175  t('0.0', '0.0007035', 1);
176  t('-0.00000000000000374916', '-0.0000000000000037491685778894015479084539735777088', 20);
177  t('534883638.00', '534883638', 2);
178  t('-2.0', '-2', 1);
179  t('-5634442247266825358399629799939027370665.0000000000000000000', '-5634442247266825358399629799939027370665', 19);
180  t('3331187169219186569122.000000000', '3331187169219186569122', 9);
181  t('0.0000000000', '0.0000000000006604395609805032330367635527', 10);
182  t('-0.0000000000000576901', '-0.00000000000005769013292086168690493327', 19);
183  t('-661.8', '-661.828596629053201916486', 1);
184  t('-6073555395665254434249128854999349235744174928042756.1153000000000', '-6073555395665254434249128854999349235744174928042756.1153', 13);
185  t('-5013086846966.000', '-5013086846966', 3);
186  t('0.004015', '0.00401523226833', 6);
187  t('3140295374107374579919222510.1462722', '3140295374107374579919222510.1462722819395532', 7);
188  t('-0.000000', '-0.00000000000000799876460379334679831886', 6);
189  t('-0.00', '-0.0003', 2);
190  t('-0.026760766726884267', '-0.026760766726884267750393307117624838556001925491', 18);
191  t('-20821740502968847857923433558797.0899', '-20821740502968847857923433558797.08997487843745', 4);
192  t('0.00000000002', '0.000000000020346524414696573703092255317751132892', 11);
193  t('45492073832204366341299301624.000000000', '45492073832204366341299301624', 9);
194
195  Decimal.rounding = 2;
196
197  t('7810971819938620325901899057970512790433.0000000000000000', '7810971819938620325901899057970512790433', 16);
198  t('-623395.0', '-623395', 1);
199  t('81334094079413997693749807.000000000000', '81334094079413997693749807', 12);
200  t('790143966.5', '790143966.406169480041929356421', 1);
201  t('-0.000485', '-0.0004851099615478', 6);
202  t('843581583868277359263.9721265', '843581583868277359263.97212648230399373761717', 7);
203  t('-921038771017147427324121032.000000', '-921038771017147427324121032', 6);
204  t('-823.0', '-823', 1);
205  t('505.0', '505', 1);
206  t('-866703339332502.8636000', '-866703339332502.8636', 7);
207  t('46.0', '46', 1);
208  t('60042202798790129685.0000000', '60042202798790129685', 7);
209  t('-1847392.0000', '-1847392', 4);
210  t('-4580251343840510165820631684073999841789879.0000000000000000000000', '-4580251343840510165820631684073999841789879', 22);
211  t('3501378778000.539063748827265447', '3501378778000.5390637488272654464266281832626835121535730779', 18);
212  t('0.000000004686', '0.000000004685387489140232', 12);
213  t('-0.0', '-0.0006', 1);
214  t('-445677508.00', '-445677508', 2);
215  t('0.0002', '0.00015099822561012723', 4);
216  t('-2992505698074499692367794831646886.0000000000000000', '-2992505698074499692367794831646886', 16);
217  t('5297873.59', '5297873.5869265978056497873793730268', 2);
218  t('72978439324039191443182.00000000000', '72978439324039191443182', 11);
219  t('0.66028387', '0.660283869505570207917431271006277981914716620876', 8);
220  t('-232008389442485.0', '-232008389442485', 1);
221  t('-2.371568', '-2.37156855939356279513952542004820909', 6);
222  t('731916154123696.1935', '731916154123696.193488323779184681349292529227446', 4);
223  t('-793941153937799250384382615553258074.00000', '-793941153937799250384382615553258074', 5);
224  t('651002.00', '651002', 2);
225  t('-61317874871.00', '-61317874871', 2);
226  t('8673.00', '8673', 2);
227  t('-14490519736189597435728386282.030655', '-14490519736189597435728386282.0306558561264348956674', 6);
228  t('0.001', '0.00000000000002', 3);
229  t('0.000009', '0.000008920984342', 6);
230  t('0.0000920957086395973679873', '0.000092095708639597367987279557138375172816422475', 25);
231  t('28125849913667924088615.25407023317734', '28125849913667924088615.2540702331773399078402875044891', 14);
232  t('87.55538597', '87.55538596435839691343147', 8);
233  t('939705902083425775202905619379.0000000', '939705902083425775202905619379', 7);
234  t('7303936681469130614.8345000', '7303936681469130614.8345', 7);
235  t('-5831852886782.68010000', '-5831852886782.6801', 8);
236  t('-0.0000000', '-0.0000000213769530812', 7);
237
238  Decimal.rounding = 3;
239
240  t('0.0000', '0.00000000000584', 4);
241  t('-79055907138737329232.165677999092552368', '-79055907138737329232.1656779990925523674', 18);
242  t('47206303530045536472421888342339.00000000', '47206303530045536472421888342339', 8);
243  t('3974.0', '3974', 1);
244  t('1296297430771.39', '1296297430771.391670729445980444292', 2);
245  t('0.000016', '0.00001686928031', 6);
246  t('-0.00001', '-0.0000000000008', 5);
247  t('4883938724383.000', '4883938724383', 3);
248  t('-5.4115622307', '-5.411562230628539329345282639155988044655000352687981880842', 10);
249  t('-0.01', '-0.0000000000155280115429218804426906540524', 2);
250  t('-2730930776035874709906.00000', '-2730930776035874709906', 5);
251  t('8419336352549424092369623.00000', '8419336352549424092369623', 5);
252  t('52897.4', '52897.4', 1);
253  t('-783171007682720320053252521365465473997085.0', '-783171007682720320053252521365465473997085', 1);
254  t('0.8', '0.8', 1);
255  t('-0.00000000085280', '-0.000000000852796916216780032747621063045628213284', 14);
256  t('809486781065644418.9', '809486781065644418.939', 1);
257  t('-9.0', '-9', 1);
258  t('2399395.00', '2399395', 2);
259  t('-243707862514768528758611224374.0000000000000', '-243707862514768528758611224374', 13);
260  t('-87906.00', '-87906', 2);
261  t('-36206954271055061276640398631031143034683624940748.9970000000000000000000', '-36206954271055061276640398631031143034683624940748.997', 22);
262  t('0.00', '0.0000000000565885579252765288683939564608114096713', 2);
263  t('-8391656174313988740342135972218668561645437.0', '-8391656174313988740342135972218668561645437', 1);
264  t('2798706581453003.177239111', '2798706581453003.17723911167031', 9);
265  t('607781292230803273523112111.091726721140', '607781292230803273523112111.09172672114', 12);
266  t('-0.3', '-0.3', 1);
267  t('3008522535782692059736852844809784198247000184.0', '3008522535782692059736852844809784198247000184', 1);
268  t('14227.00', '14227', 2);
269  t('7841760307718014116576857993957.0000', '7841760307718014116576857993957', 4);
270  t('-0.00001', '-0.00000000000002596', 5);
271  t('5247199732982111073.000000000', '5247199732982111073', 9);
272  t('-12.0', '-12', 1);
273  t('0.000', '0.00005', 3);
274  t('-1383703062.0000', '-1383703062', 4);
275  t('0.0051019245305169', '0.00510192453051698060366202631871161193', 16);
276  t('-45565092550117861497905653558246322559799.0', '-45565092550117861497905653558246322559799', 1);
277  t('-0.284', '-0.284', 3);
278  t('-8962.00', '-8962', 2);
279  t('49335989571.2173023', '49335989571.217302304037', 7);
280
281  Decimal.rounding = 4;
282  Decimal.toExpNeg = Decimal.toExpPos = 0;
283
284  t('733744593401073823825766410831877679446.0000000000000000000', '733744593401073823825766410831877679446', 19);
285  t('-64.6849459', '-64.6849458687691227978', 7);
286  t('-0.000000', '-0.00000000009', 6);
287  t('-62537287527837589298857228059657673223234916.95923265430000000', '-62537287527837589298857228059657673223234916.9592326543', 17);
288  t('3393668096256773847245721315080265089731.000000', '3393668096256773847245721315080265089731', 6);
289  t('0.0', '0.0000000000000056674956638008432348702401392', 1);
290  t('72516372734.6', '72516372734.6447', 1);
291  t('-418.28', '-418.2800731793741351', 2);
292  t('0.00', '0.001', 2);
293  t('8366217346845756726.00000000', '8366217346845756726', 8);
294  t('-0.000000', '-0.0000000000000092034548636370987112234384736726', 6);
295  t('0.35', '0.35474830751442135112334772517193392', 2);
296  t('64703289793894.5830', '64703289793894.58296866', 4);
297  t('-0.000000000000000036', '-0.000000000000000036461242408590182363418943891', 18);
298  t('5494508405056449117588.631948', '5494508405056449117588.631948458033233759999', 6);
299  t('-0.0', '-0.00393971618499838726739122333520030506235698', 1);
300  t('375581290738585826632.00000000', '375581290738585826632', 8);
301  t('254.96635275802300887', '254.96635275802300886544776010389418575738792480979736', 17);
302  t('21492347.69467571391498624445', '21492347.6946757139149862444482880595559468', 20);
303  t('313576441324233.0000000', '313576441324233', 7);
304  t('-534460490015293367127173277346694900936058.0000', '-534460490015293367127173277346694900936058', 4);
305  t('182707431911537249021116759327712693311898345504618668.43327000000000000000000', '182707431911537249021116759327712693311898345504618668.43327', 23);
306  t('210005324615278.4586839690045963321032', '210005324615278.458683969004596332103244549279', 22);
307  t('779837001772884165637922377221951347134695.644834', '779837001772884165637922377221951347134695.6448338', 6);
308  t('-0.000001', '-0.00000064188301390033596845335767993853284632527964514979079', 6);
309  t('13.0', '13', 1);
310  t('0.0000001269', '0.0000001269060795648365813491128357427111184222', 10);
311  t('18446632248354.00', '18446632248354', 2);
312  t('-1229249.79', '-1229249.7897249259', 2);
313  t('49082.0', '49082', 1);
314  t('-61.0', '-61', 1);
315  t('-893.0', '-893', 1);
316  t('5002282278.56974877690066484', '5002282278.569748776900664839184116538222902', 17);
317  t('41372.00', '41372', 2);
318  t('-4732022445962399687294885123498809.7625585825095', '-4732022445962399687294885123498809.7625585825095', 13);
319  t('-55484242.036895641', '-55484242.036895641', 9);
320  t('-41427133134.52583323427907663268339', '-41427133134.525833234279076632683393992706825', 23);
321  t('0.0', '0.00004300614085218825243480119971669264977421', 1);
322  t('-472025754597316278339412186866.7010659789', '-472025754597316278339412186866.701065978877597089729906019843', 10);
323
324  Decimal.rounding = 5;
325
326  t('0.00', '0.00000000000000070362', 2);
327  t('682377946933004839.0000000', '682377946933004839', 7);
328  t('0.000000000', '0.00000000000000301722508588270616971784651380892069087869575', 9);
329  t('-356330174906.7', '-356330174906.737986270704', 1);
330  t('771875969530483104163034745359742192923504.000000000000000', '771875969530483104163034745359742192923504', 15);
331  t('-85.57612133364', '-85.576121333642541652128540737082', 11);
332  t('-796870619982006783.00000000', '-796870619982006783', 8);
333  t('985819.0', '985819', 1);
334  t('0.000000', '0.00000000000000000007093034243958', 6);
335  t('-0.0000', '-0.0000000006400178083107075310177579449', 4);
336  t('-105570971372984.0', '-105570971372984', 1);
337  t('4387745564661852845308.94229815083918', '4387745564661852845308.9422981508391799473309882', 14);
338  t('-3978043797116373.2', '-3978043797116373.159631', 1);
339  t('5.8961281424853232622595', '5.8961281424853232622594846548715356650909645537495738043051', 22);
340  t('-0.0000081539970551874384495', '-0.000008153997055187438449482684680130340977472796176926', 25);
341  t('-65.0', '-65', 1);
342  t('-24012940205869.000', '-24012940205869', 3);
343  t('0.000000', '0.000000000000000066985234999507396', 6);
344  t('2935194283452.35738951157832206907124', '2935194283452.357389511578322069071242729133894', 23);
345  t('542060.7771', '542060.77713479586821060591807145320317', 4);
346  t('890815036528241639534803534813.592588608837168425865025', '890815036528241639534803534813.59258860883716842586502472472', 24);
347  t('685877749980391051.17', '685877749980391051.1715', 2);
348  t('47820177163147405231185068730213.894293', '47820177163147405231185068730213.89429254869826585947429821', 6);
349  t('1536364305.00', '1536364305', 2);
350  t('-85825125.5810188', '-85825125.5810188298', 7);
351  t('-4983288214158634188.4572989', '-4983288214158634188.4572988600705359104', 7);
352  t('0.0000000000', '0.0000000000000000017929073', 10);
353  t('-1684136337600384671.00000000', '-1684136337600384671', 8);
354  t('567733137127609543.000000', '567733137127609543', 6);
355  t('607675679770387.000', '607675679770387', 3);
356  t('43727409067319.0', '43727409067319', 1);
357  t('-77274559773372606.00', '-77274559773372606', 2);
358  t('-28855643486070486857836.00000', '-28855643486070486857836', 5);
359  t('-915356570870.00', '-915356570870.00041832252262829437239', 2);
360  t('0.0', '0.00000000000004843552301428650828', 1);
361
362  Decimal.rounding = 6;
363
364  t('-6614662975368684488885953285955838893900074215956.00', '-6614662975368684488885953285955838893900074215956', 2);
365  t('8642393776898.000', '8642393776898', 3);
366  t('3612207878528.1106344698085142865', '3612207878528.1106344698085142865438924419', 19);
367  t('977910386.93', '977910386.9343537', 2);
368  t('-8937937492688941768401276851642629965923372.0', '-8937937492688941768401276851642629965923372', 1);
369  t('-8327876772303865517454752161.4376112752921904774', '-8327876772303865517454752161.43761127529219047742910886', 19);
370  t('-27707.00', '-27707', 2);
371  t('-7287595765894242586375.92700435484', '-7287595765894242586375.927004354837723619581861634319', 11);
372  t('-0.00000', '-0.000000000000023670858459165486137218740358207859', 5);
373  t('574676836802209077.64156', '574676836802209077.641563875647945277493356873895', 5);
374  t('-3041038455237222898218053653661.87952947815', '-3041038455237222898218053653661.87952947815', 11);
375  t('-628244132307.000', '-628244132307', 3);
376  t('316566935167341670725238.000', '316566935167341670725238', 3);
377  t('-77953301569468294124105528.0', '-77953301569468294124105528', 1);
378  t('0.0046', '0.00460227833968584', 4);
379  t('4323265763616518980379929221104.0', '4323265763616518980379929221104', 1);
380  t('1674500565014237781637959673471730398.1120033', '1674500565014237781637959673471730398.1120032995511774', 7);
381  t('872559441430499650732600166.00000', '872559441430499650732600166', 5);
382  t('-87858304.0000', '-87858304', 4);
383  t('-4158788.000', '-4158788', 3);
384  t('3983930437416823631395.9093', '3983930437416823631395.90934402583657', 4);
385  t('-14.5531937', '-14.5531936852106573016020290135814233645752955297443336', 7);
386  t('0.00000000002201', '0.00000000002200503795474854372849141363413146996972', 14);
387  t('0.0000000000000', '0.00000000000000000894955653982033503846831364474746320232', 13);
388  t('61564779.00', '61564779', 2);
389  t('-7.0', '-7', 1);
390  t('-0.000000000000028455976228', '-0.00000000000002845597622815028653703372125435938812845106', 24);
391  t('728982423193598397582409707715766595902844.0000000', '728982423193598397582409707715766595902844', 7);
392  t('14538075860529.2697937480', '14538075860529.269793748', 10);
393  t('0.000', '0.00000000000000000007021566096', 3);
394  t('-5136066535080.86830591678842264063462546263', '-5136066535080.86830591678842264063462546262988980471309228558', 29);
395  t('-3026751112367460839746524832112404665.000000000000000', '-3026751112367460839746524832112404665', 15);
396
397  t('0.5', '0.5');
398  t('-0', '-0.5', 0);
399  t('10.5', '10.5');
400  t('0.05', '0.05');
401  t('0.4', '0.4');
402  t('0.6', '0.6');
403  t('1.5', '1.5');
404  t('-1.5', '-1.5');
405
406  Decimal.rounding = 4;
407
408  t('-535564000.00', '-535564000', 2);
409  t('-80000000.000', '-80000000', 3);
410  t('-240.0', '-240', 1);
411  t('-7520000000.0', '-7520000000', 1);
412  t('306550.000', '306550', 3);
413  t('800000000.0', '800000000', 1);
414  t('-454000000.00000', '-454000000', 5);
415  t('60.0', '60', 1);
416  t('-4700000.000', '-4700000', 3);
417  t('25000.00', '25000', 2);
418  t('6847.0', '6847', 1);
419  t('780.0', '780', 1);
420  t('-50.0', '-50', 1);
421  t('700.0', '700', 1);
422  t('412598000.0000', '412598000', 4);
423  t('-84581600.0', '-84581600', 1);
424  t('5590000.00', '5590000', 2);
425  t('-66000.0', '-66000', 1);
426  t('600.0', '600', 1);
427  t('-513335000.000', '-513335000', 3);
428  t('-40.0', '-40', 1);
429
430  t('-52536202527.13891931933498708496518913773517016037224', '-5.253620252713891931933498708496518913773517016037224E10');
431  t('0.0000000000000008761383898703999300297605784533730922', '8.761383898703999300297605784533730922E-16');
432  t('-0.0000000000000000000000000000000000004', '-4E-37');
433  t('2832044194940.47654015529986948208', '2.83204419494047654015529986948208E12');
434  t('0.00000000000000000000000064668155275864837', '6.4668155275864837E-25');
435  t('4.34128088694', '4.34128088694E0');
436  t('-851957.6572615611436542', '-8.519576572615611436542E5');
437  t('-89097468286.2561077879598798580253771544265682053', '-8.90974682862561077879598798580253771544265682053E10');
438  t('-0.000000000000000000000000000000000000000000000030409767', '-3.0409767E-47');
439  t('0.000000000000000000004295112484112357722747956581254', '4.295112484112357722747956581254E-21');
440  t('-839203207475651.6542808578', '-8.392032074756516542808578E14');
441  t('-0.00000000000000000078216', '-7.8216E-19');
442  t('-1782290274935701247734.21262413032385', '-1.78229027493570124773421262413032385E21');
443  t('31669451104144801337076433457.18511076', '3.166945110414480133707643345718511076E28');
444  t('0.000000000000000000000000000000000000472351852761', '4.72351852761E-37');
445  t('-50155220217523568901083623.78842580174913602672593731', '-5.015522021752356890108362378842580174913602672593731E25');
446  t('-291.37', '-2.9137E2');
447  t('-52474611936456205886027195352961212383.2279441143', '-5.24746119364562058860271953529612123832279441143E37');
448  t('-326.9376463292543', '-3.269376463292543E2');
449  t('0.00000000000044', '4.4E-13');
450  t('0.000000087792449', '8.7792449E-8');
451  t('497835793870987132484033.938845920610565887398960253648', '4.97835793870987132484033938845920610565887398960253648E23');
452  t('-33960439442302770058.74863962', '-3.396043944230277005874863962E19');
453  t('0.00000000000000000000000000000000000000020694696587293782', '2.0694696587293782E-40');
454
455  t('123.45', '123.45');
456  t('123', '123.45', 0);
457  t('123', '123.45', -0);
458
459  tx(function () {new Decimal(1.23).toFixed('3')}, "(1.23).toFixed('3')");
460  tx(function () {new Decimal(1.23).toFixed(new Decimal('3'))}, "(1.23).toFixed(new Decimal('3'))");
461  tx(function () {new Decimal(1.23).toFixed(null)}, "(1.23).toFixed(null)");
462  tx(function () {new Decimal(1.23).toFixed(NaN)}, "(1.23).toFixed(NaN)");
463  tx(function () {new Decimal(1.23).toFixed('NaN')}, "(1.23).toFixed('NaN')");
464  tx(function () {new Decimal(1.23).toFixed([])}, "(1.23).toFixed([])");
465  tx(function () {new Decimal(1.23).toFixed({})}, "(1.23).toFixed({})");
466  tx(function () {new Decimal(1.23).toFixed('')}, "(1.23).toFixed('')");
467  tx(function () {new Decimal(1.23).toFixed(' ')}, "(1.23).toFixed(' ')");
468  tx(function () {new Decimal(1.23).toFixed('hello')}, "(1.23).toFixed('hello')");
469  tx(function () {new Decimal(1.23).toFixed('\t')}, "(1.23).toFixed('\t')");
470  tx(function () {new Decimal(1.23).toFixed(new Date)}, "(1.23).toFixed(new Date)");
471  tx(function () {new Decimal(1.23).toFixed(new RegExp)}, "(1.23).toFixed(new RegExp)");
472  tx(function () {new Decimal(1.23).toFixed(2.01)}, "(1.23).toFixed(2.01)");
473  tx(function () {new Decimal(1.23).toFixed(10.5)}, "(1.23).toFixed(10.5)");
474  tx(function () {new Decimal(1.23).toFixed('1.1e1')}, "(1.23).toFixed('1.1e1')");
475  tx(function () {new Decimal(1.23).toFixed(true)}, "(1.23).toFixed(true)");
476  tx(function () {new Decimal(1.23).toFixed(false)}, "(1.23).toFixed(false)");
477  tx(function () {new Decimal(1.23).toFixed(function (){})}, "(1.23).toFixed(function (){})");
478
479  tx(function () {new Decimal('123.45').toFixed(1e9 + 1)}, ".toFixed(1e9 + 1)");
480  tx(function () {new Decimal('123.45').toFixed('-0.01')}, ".toFixed('-0.01')");
481  tx(function () {new Decimal('123.45').toFixed('-1e-1')}, ".toFixed('-1e-1')");
482  tx(function () {new Decimal('123.45').toFixed(Infinity)}, ".toFixed(Infinity)");
483  tx(function () {new Decimal('123.45').toFixed('-Infinity')}, ".toFixed('-Infinity')");
484
485  tx(function () {new Decimal(1.23).toFixed(1, '3')}, "(1.23).toFixed(1, '3')");
486  tx(function () {new Decimal(1.23).toFixed(1, new Decimal('3'))}, "(1.23).toFixed(1, new Decimal('3'))");
487  tx(function () {new Decimal(1.23).toFixed(1, null)}, "(1.23).toFixed(1, null)");
488  tx(function () {new Decimal(1.23).toFixed(1, NaN)}, "(1.23).toFixed(1, NaN)");
489  tx(function () {new Decimal(1.23).toFixed(1, 'NaN')}, "(1.23).toFixed(1, 'NaN')");
490  tx(function () {new Decimal(1.23).toFixed(1, [])}, "(1.23).toFixed(1, [])");
491  tx(function () {new Decimal(1.23).toFixed(1, {})}, "(1.23).toFixed(1, {})");
492  tx(function () {new Decimal(1.23).toFixed(1, '')}, "(1.23).toFixed(1, '')");
493  tx(function () {new Decimal(1.23).toFixed(1, ' ')}, "(1.23).toFixed(1, ' ')");
494  tx(function () {new Decimal(1.23).toFixed(1, 'hello')}, "(1.23).toFixed(1, 'hello')");
495  tx(function () {new Decimal(1.23).toFixed(1, '\t')}, "(1.23).toFixed(1, '\t')");
496  tx(function () {new Decimal(1.23).toFixed(1, new Date)}, "(1.23).toFixed(1, new Date)");
497  tx(function () {new Decimal(1.23).toFixed(1, new RegExp)}, "(1.23).toFixed(1, new RegExp)");
498  tx(function () {new Decimal(1.23).toFixed(1, 2.01)}, "(1.23).toFixed(1, 2.01)");
499  tx(function () {new Decimal(1.23).toFixed(1, 10.5)}, "(1.23).toFixed(1, 10.5)");
500  tx(function () {new Decimal(1.23).toFixed(1, '1.1e1')}, "(1.23).toFixed(1, '1.1e1')");
501  tx(function () {new Decimal(1.23).toFixed(1, true)}, "(1.23).toFixed(1, true)");
502  tx(function () {new Decimal(1.23).toFixed(1, false)}, "(1.23).toFixed(1, false)");
503  tx(function () {new Decimal(1.23).toFixed(1, function (){})}, "(1.23).toFixed(1, function (){})");
504
505  tx(function () {new Decimal('123.45').toFixed(1, 9)}, ".toFixed(1, 9)");
506  tx(function () {new Decimal('123.45').toFixed(1, '-0.01')}, ".toFixed(1, '-0.01')");
507  tx(function () {new Decimal('123.45').toFixed(1, '-1e-1')}, ".toFixed(1, '-1e-1')");
508  tx(function () {new Decimal('123.45').toFixed(1, Infinity)}, ".toFixed(1, Infinity)");
509  tx(function () {new Decimal('123.45').toFixed(1, '-Infinity')}, ".toFixed(1, '-Infinity')");
510
511  // ROUND_HALF_CEIL
512  // Rounds towards nearest neighbour. If equidistant, rounds towards Infinity
513  Decimal.rounding = 7;
514
515  t('0.1', '0.05', 1);
516  t('1', 0.5, 0);
517  t('1', 0.54, 0);
518  t('1', 0.55, 0);
519  t('1', 0.56, 0);
520  t('-1', -0.54, 0);
521  t('-0', -0.5, 0);
522  t('-1', -0.56, 0);
523  t('-0.5', -0.5, 1);
524  t('1.3', 1.25, 1);
525  t('-1.2', -1.25, 1);
526  t('234.2041', 234.20405, 4);
527  t('-234.2040', -234.20405, 4);
528  t('234.2041', '234.204050000000000000000000000000006', 4);
529  t('-234.2045', '-234.20449', 4);
530  t('-234.2041', '-234.204050000000000000000000000000006', 4);
531  t('999.0', 999, 1);
532  t('1000', 999.5, 0);
533  t('-999', -999.5, 0);
534  t('-999.5', -999.5, 1);
535  t('1.00000000000000000', '1.000000000000000000005', 17)
536  t('1.00000000000000000001', '1.000000000000000000005', 20)
537  t('-1.00000000000000000', '-1.000000000000000000005', 17)
538  t('-1.00000000000000000000', '-1.000000000000000000005', 20)
539
540  // ROUND_HALF_FLOOR
541  // Rounds towards nearest neighbour. If equidistant, rounds towards -Infinity
542  Decimal.rounding = 8;
543
544  t('0.0', '0.05', 1);
545  t('0', 0.5, 0);
546  t('1', 0.54, 0);
547  t('1', 0.55, 0);
548  t('1', 0.56, 0);
549  t('-1', -0.54, 0);
550  t('-1', -0.5, 0);
551  t('-1', -0.56, 0);
552  t('-0.5', -0.5, 1);
553  t('1.2', 1.25, 1);
554  t('-1.3', -1.25, 1);
555  t('234.2040', 234.20405, 4);
556  t('-234.2041', -234.20405, 4);
557  t('234.2040', '234.20404999999999999999999999999999', 4);
558  t('234.2041', '234.204050000000000000000000000000006', 4);
559  t('-234.2045', '-234.20449', 4);
560  t('-234.2041', '-234.204050000000000000000000000000006', 4);
561  t('999.0', 999, 1);
562  t('999', 999.5, 0);
563  t('-1000', -999.5, 0);
564  t('-999.5', -999.5, 1);
565  t('1.00000000000000000', '1.000000000000000000005', 17);
566  t('1.00000000000000000000', '1.000000000000000000005', 20);
567  t('-1.00000000000000000', '-1.000000000000000000005', 17);
568  t('-1.00000000000000000001', '-1.000000000000000000005', 20);
569});
570