@keplr-wallet/unit 0.9.10 → 0.9.12-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/coin-pretty.d.ts +13 -3
- package/build/coin-pretty.js +36 -25
- package/build/coin-pretty.js.map +1 -1
- package/build/coin-pretty.spec.js +194 -9
- package/build/coin-pretty.spec.js.map +1 -1
- package/build/coin-utils.js +8 -4
- package/build/coin-utils.js.map +1 -1
- package/build/coin-utils.spec.js +16 -0
- package/build/coin-utils.spec.js.map +1 -1
- package/build/coin.js +1 -1
- package/build/coin.js.map +1 -1
- package/build/coin.spec.js +15 -0
- package/build/coin.spec.js.map +1 -1
- package/build/dec-utils.d.ts +8 -1
- package/build/dec-utils.js +22 -20
- package/build/dec-utils.js.map +1 -1
- package/build/dec-utils.spec.js +19 -0
- package/build/dec-utils.spec.js.map +1 -1
- package/build/decimal.d.ts +22 -9
- package/build/decimal.js +102 -29
- package/build/decimal.js.map +1 -1
- package/build/decimal.spec.js +296 -3
- package/build/decimal.spec.js.map +1 -1
- package/build/etc.d.ts +4 -0
- package/build/etc.js +66 -0
- package/build/etc.js.map +1 -0
- package/build/etc.spec.d.ts +1 -0
- package/build/etc.spec.js +66 -0
- package/build/etc.spec.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/int-pretty.d.ts +16 -4
- package/build/int-pretty.js +74 -36
- package/build/int-pretty.js.map +1 -1
- package/build/int-pretty.spec.js +261 -94
- package/build/int-pretty.spec.js.map +1 -1
- package/build/int.d.ts +17 -12
- package/build/int.js +69 -16
- package/build/int.js.map +1 -1
- package/build/int.spec.d.ts +1 -0
- package/build/int.spec.js +161 -0
- package/build/int.spec.js.map +1 -0
- package/build/price-pretty.d.ts +13 -3
- package/build/price-pretty.js +37 -26
- package/build/price-pretty.js.map +1 -1
- package/build/price-pretty.spec.js +59 -2
- package/build/price-pretty.spec.js.map +1 -1
- package/build/rate-pretty.d.ts +57 -0
- package/build/rate-pretty.js +128 -0
- package/build/rate-pretty.js.map +1 -0
- package/build/rate-pretty.spec.d.ts +1 -0
- package/build/rate-pretty.spec.js +38 -0
- package/build/rate-pretty.spec.js.map +1 -0
- package/package.json +3 -3
- package/src/coin-pretty.spec.ts +304 -11
- package/src/coin-pretty.ts +56 -29
- package/src/coin-utils.spec.ts +32 -0
- package/src/coin-utils.ts +12 -4
- package/src/coin.spec.ts +20 -0
- package/src/coin.ts +1 -1
- package/src/dec-utils.spec.ts +39 -0
- package/src/dec-utils.ts +25 -20
- package/src/decimal.spec.ts +361 -3
- package/src/decimal.ts +135 -56
- package/src/etc.spec.ts +73 -0
- package/src/etc.ts +73 -0
- package/src/index.ts +1 -0
- package/src/int-pretty.spec.ts +296 -101
- package/src/int-pretty.ts +87 -34
- package/src/int.spec.ts +212 -0
- package/src/int.ts +94 -26
- package/src/price-pretty.spec.ts +106 -2
- package/src/price-pretty.ts +50 -30
- package/src/rate-pretty.spec.ts +52 -0
- package/src/rate-pretty.ts +165 -0
package/src/dec-utils.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import { Dec } from "./decimal";
|
2
|
+
import { Int } from "./int";
|
2
3
|
|
3
4
|
export class DecUtils {
|
4
|
-
static trim(dec: Dec | string): string {
|
5
|
+
public static trim(dec: Dec | string): string {
|
5
6
|
let decStr = typeof dec === "string" ? dec : dec.toString();
|
6
7
|
|
7
8
|
if (decStr.indexOf(".") < 0) {
|
@@ -25,33 +26,37 @@ export class DecUtils {
|
|
25
26
|
return decStr;
|
26
27
|
}
|
27
28
|
|
28
|
-
|
29
|
+
protected static tenExponentNs: { [n: string]: Dec } = {};
|
29
30
|
|
30
|
-
static
|
31
|
-
if (
|
31
|
+
public static getTenExponentN(n: number): Dec {
|
32
|
+
if (n < -Dec.precision) {
|
33
|
+
// Dec can only handle up to precision 18.
|
34
|
+
// Anything less than 18 precision is 0, so there is a high probability of an error.
|
32
35
|
throw new Error("Too little precision");
|
33
36
|
}
|
34
|
-
if (precision > 18) {
|
35
|
-
throw new Error("Too much precision");
|
36
|
-
}
|
37
37
|
|
38
|
-
if (DecUtils.
|
39
|
-
return DecUtils.
|
38
|
+
if (DecUtils.tenExponentNs[n.toString()]) {
|
39
|
+
return DecUtils.tenExponentNs[n.toString()];
|
40
40
|
}
|
41
41
|
|
42
|
-
|
42
|
+
const dec = new Dec(10).pow(new Int(n));
|
43
|
+
DecUtils.tenExponentNs[n.toString()] = dec;
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
dec = dec.quo(new Dec(10));
|
51
|
-
}
|
45
|
+
return dec;
|
46
|
+
}
|
47
|
+
|
48
|
+
public static getTenExponentNInPrecisionRange(n: number): Dec {
|
49
|
+
if (n > Dec.precision) {
|
50
|
+
throw new Error("Too much precision");
|
52
51
|
}
|
53
52
|
|
54
|
-
DecUtils.
|
55
|
-
|
53
|
+
return DecUtils.getTenExponentN(n);
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* @deprecated Use`getTenExponentNInPrecisionRange`
|
58
|
+
*/
|
59
|
+
public static getPrecisionDec(precision: number): Dec {
|
60
|
+
return DecUtils.getTenExponentNInPrecisionRange(precision);
|
56
61
|
}
|
57
62
|
}
|
package/src/decimal.spec.ts
CHANGED
@@ -2,7 +2,19 @@ import { Dec } from "./decimal";
|
|
2
2
|
import { Int } from "./int";
|
3
3
|
|
4
4
|
describe("Test decimals", () => {
|
5
|
-
|
5
|
+
// (2 ** (256 + 60) - 1) / (10 ** 18)
|
6
|
+
const maxDec =
|
7
|
+
"133499189745056880149688856635597007162669032647290798121690100488888732861290.034376435130433535";
|
8
|
+
// maxDec + 0.000000000000000001
|
9
|
+
const overflowedDec =
|
10
|
+
"133499189745056880149688856635597007162669032647290798121690100488888732861290.034376435130433536";
|
11
|
+
|
12
|
+
it("dec should be parsed properly", () => {
|
13
|
+
expect(() => new Dec(1, 0)).not.toThrow();
|
14
|
+
expect(() => new Dec(1, -1)).toThrow();
|
15
|
+
expect(() => new Dec(1, Dec.precision)).not.toThrow();
|
16
|
+
expect(() => new Dec(1, Dec.precision + 1)).toThrow();
|
17
|
+
|
6
18
|
let dec = new Dec("10.009");
|
7
19
|
expect(dec.toString()).toBe("10.009000000000000000");
|
8
20
|
expect(dec.toString(2)).toBe("10.00");
|
@@ -14,6 +26,17 @@ describe("Test decimals", () => {
|
|
14
26
|
dec = new Dec("10");
|
15
27
|
expect(dec.toString()).toBe("10.000000000000000000");
|
16
28
|
|
29
|
+
dec = new Dec(10);
|
30
|
+
expect(dec.toString()).toBe("10.000000000000000000");
|
31
|
+
|
32
|
+
dec = new Dec(10.009);
|
33
|
+
expect(dec.toString()).toBe("10.009000000000000000");
|
34
|
+
expect(dec.toString(2)).toBe("10.00");
|
35
|
+
|
36
|
+
dec = new Dec(-123.456789);
|
37
|
+
expect(dec.toString()).toBe("-123.456789000000000000");
|
38
|
+
expect(dec.toString(3)).toBe("-123.456");
|
39
|
+
|
17
40
|
expect(() => {
|
18
41
|
new Dec("");
|
19
42
|
}).toThrow();
|
@@ -22,7 +45,7 @@ describe("Test decimals", () => {
|
|
22
45
|
}).toThrow();
|
23
46
|
expect(() => {
|
24
47
|
new Dec("0.489234893284938249348923849283408");
|
25
|
-
}).toThrow();
|
48
|
+
}).not.toThrow();
|
26
49
|
expect(() => {
|
27
50
|
new Dec("foobar");
|
28
51
|
}).toThrow();
|
@@ -34,6 +57,147 @@ describe("Test decimals", () => {
|
|
34
57
|
}).toThrow();
|
35
58
|
});
|
36
59
|
|
60
|
+
it("Test Dec overflow", () => {
|
61
|
+
expect(new Dec(maxDec).toString()).toBe(maxDec);
|
62
|
+
expect(new Dec("-" + maxDec).toString()).toBe("-" + maxDec);
|
63
|
+
|
64
|
+
expect(() => new Dec(overflowedDec)).toThrow();
|
65
|
+
expect(() => new Dec("-" + overflowedDec)).toThrow();
|
66
|
+
|
67
|
+
const max = new Dec(maxDec);
|
68
|
+
expect(() => max.add(new Dec(1, Dec.precision))).toThrow();
|
69
|
+
|
70
|
+
const min = new Dec("-" + maxDec);
|
71
|
+
expect(() => min.sub(new Dec(1, Dec.precision))).toThrow();
|
72
|
+
});
|
73
|
+
|
74
|
+
it("Test Dec neg/abs", () => {
|
75
|
+
expect(new Dec(1).neg().toString()).toBe("-1.000000000000000000");
|
76
|
+
expect(new Dec(1).neg().equals(new Dec(-1))).toBe(true);
|
77
|
+
|
78
|
+
expect(new Dec(-1).neg().toString()).toBe("1.000000000000000000");
|
79
|
+
expect(new Dec(-1).neg().equals(new Dec(1))).toBe(true);
|
80
|
+
|
81
|
+
expect(new Dec(1).abs().toString()).toBe("1.000000000000000000");
|
82
|
+
expect(new Dec(1).abs().equals(new Dec(1))).toBe(true);
|
83
|
+
|
84
|
+
expect(new Dec(-1).abs().toString()).toBe("1.000000000000000000");
|
85
|
+
expect(new Dec(-1).abs().equals(new Dec(1))).toBe(true);
|
86
|
+
});
|
87
|
+
|
88
|
+
it("Test Dec isPositive/isNegative/isInteger/isZero", () => {
|
89
|
+
expect(new Dec(1).isPositive()).toBe(true);
|
90
|
+
expect(new Dec(-1).isPositive()).toBe(false);
|
91
|
+
|
92
|
+
expect(new Dec(1).isNegative()).toBe(false);
|
93
|
+
expect(new Dec(-1).isNegative()).toBe(true);
|
94
|
+
|
95
|
+
expect(new Dec(1).isInteger()).toBe(true);
|
96
|
+
expect(new Dec(-1).isInteger()).toBe(true);
|
97
|
+
|
98
|
+
expect(new Dec(1.1).isInteger()).toBe(false);
|
99
|
+
expect(new Dec(-1.1).isInteger()).toBe(false);
|
100
|
+
|
101
|
+
expect(new Dec(0).isZero()).toBe(true);
|
102
|
+
expect(new Dec(-0).isZero()).toBe(true);
|
103
|
+
expect(new Dec(-1.1).isZero()).toBe(false);
|
104
|
+
expect(new Dec(1.1).isZero()).toBe(false);
|
105
|
+
});
|
106
|
+
|
107
|
+
it("Test Dec comparison", () => {
|
108
|
+
const dec1 = new Dec(1);
|
109
|
+
const dec2 = new Dec(2);
|
110
|
+
|
111
|
+
expect(dec1.gt(dec2)).toBe(false);
|
112
|
+
expect(dec1.gte(dec1)).toBe(true);
|
113
|
+
|
114
|
+
expect(dec1.lt(dec2)).toBe(true);
|
115
|
+
expect(dec1.lte(dec1)).toBe(true);
|
116
|
+
|
117
|
+
expect(dec1.equals(dec2)).toBe(false);
|
118
|
+
expect(dec1.equals(dec1)).toBe(true);
|
119
|
+
});
|
120
|
+
|
121
|
+
it("Test Dec power", () => {
|
122
|
+
const tests: {
|
123
|
+
d1: Dec;
|
124
|
+
i1: Int;
|
125
|
+
exp: Dec;
|
126
|
+
}[] = [
|
127
|
+
{
|
128
|
+
d1: new Dec(0),
|
129
|
+
i1: new Int(12),
|
130
|
+
exp: new Dec(0),
|
131
|
+
},
|
132
|
+
{
|
133
|
+
d1: new Dec(0),
|
134
|
+
i1: new Int(0),
|
135
|
+
exp: new Dec(1),
|
136
|
+
},
|
137
|
+
{
|
138
|
+
d1: new Dec(12),
|
139
|
+
i1: new Int(0),
|
140
|
+
exp: new Dec(1),
|
141
|
+
},
|
142
|
+
{
|
143
|
+
d1: new Dec(-12),
|
144
|
+
i1: new Int(0),
|
145
|
+
exp: new Dec(1),
|
146
|
+
},
|
147
|
+
{
|
148
|
+
d1: new Dec(-12),
|
149
|
+
i1: new Int(1),
|
150
|
+
exp: new Dec(-12),
|
151
|
+
},
|
152
|
+
{
|
153
|
+
d1: new Dec(-12),
|
154
|
+
i1: new Int(2),
|
155
|
+
exp: new Dec(144),
|
156
|
+
},
|
157
|
+
{
|
158
|
+
d1: new Dec(12),
|
159
|
+
i1: new Int(3),
|
160
|
+
exp: new Dec(1728),
|
161
|
+
},
|
162
|
+
{
|
163
|
+
d1: new Dec(12),
|
164
|
+
i1: new Int(-1),
|
165
|
+
exp: new Dec("0.083333333333333333"),
|
166
|
+
},
|
167
|
+
{
|
168
|
+
d1: new Dec(12),
|
169
|
+
i1: new Int(-2),
|
170
|
+
exp: new Dec("0.006944444444444444"),
|
171
|
+
},
|
172
|
+
{
|
173
|
+
d1: new Dec(12),
|
174
|
+
i1: new Int(-3),
|
175
|
+
exp: new Dec("0.000578703703703704"),
|
176
|
+
},
|
177
|
+
{
|
178
|
+
d1: new Dec(10),
|
179
|
+
i1: new Int(4),
|
180
|
+
exp: new Dec("10000"),
|
181
|
+
},
|
182
|
+
{
|
183
|
+
d1: new Dec(10),
|
184
|
+
i1: new Int(5),
|
185
|
+
exp: new Dec("100000"),
|
186
|
+
},
|
187
|
+
{
|
188
|
+
d1: new Dec(10),
|
189
|
+
i1: new Int(-5),
|
190
|
+
exp: new Dec("0.00001"),
|
191
|
+
},
|
192
|
+
];
|
193
|
+
|
194
|
+
for (const test of tests) {
|
195
|
+
const res = test.d1.pow(test.i1);
|
196
|
+
|
197
|
+
expect(res.toString()).toBe(test.exp.toString());
|
198
|
+
}
|
199
|
+
});
|
200
|
+
|
37
201
|
it("dec should be caculated properly", () => {
|
38
202
|
const tests: {
|
39
203
|
d1: Dec;
|
@@ -160,6 +324,64 @@ describe("Test decimals", () => {
|
|
160
324
|
});
|
161
325
|
|
162
326
|
it("dec should be round up properly", () => {
|
327
|
+
const tests: {
|
328
|
+
d1: Dec;
|
329
|
+
exp: Int;
|
330
|
+
}[] = [
|
331
|
+
{
|
332
|
+
d1: new Dec("0.25"),
|
333
|
+
exp: new Int("1"),
|
334
|
+
},
|
335
|
+
{
|
336
|
+
d1: new Dec("0"),
|
337
|
+
exp: new Int("0"),
|
338
|
+
},
|
339
|
+
{
|
340
|
+
d1: new Dec("1"),
|
341
|
+
exp: new Int("1"),
|
342
|
+
},
|
343
|
+
{
|
344
|
+
d1: new Dec("0.75"),
|
345
|
+
exp: new Int("1"),
|
346
|
+
},
|
347
|
+
{
|
348
|
+
d1: new Dec("0.5"),
|
349
|
+
exp: new Int("1"),
|
350
|
+
},
|
351
|
+
{
|
352
|
+
d1: new Dec("7.5"),
|
353
|
+
exp: new Int("8"),
|
354
|
+
},
|
355
|
+
{
|
356
|
+
d1: new Dec("0.545"),
|
357
|
+
exp: new Int("1"),
|
358
|
+
},
|
359
|
+
{
|
360
|
+
d1: new Dec("1.545"),
|
361
|
+
exp: new Int("2"),
|
362
|
+
},
|
363
|
+
{
|
364
|
+
d1: new Dec("-1.545"),
|
365
|
+
exp: new Int("-1"),
|
366
|
+
},
|
367
|
+
{
|
368
|
+
d1: new Dec("-0.545"),
|
369
|
+
exp: new Int("0"),
|
370
|
+
},
|
371
|
+
];
|
372
|
+
|
373
|
+
for (const test of tests) {
|
374
|
+
const resPos = test.d1.roundUp();
|
375
|
+
expect(resPos.toString()).toBe(test.exp.toString());
|
376
|
+
|
377
|
+
const resPosDec = test.d1.roundUpDec();
|
378
|
+
expect(resPosDec.toString()).toBe(
|
379
|
+
test.exp.toString() + ".000000000000000000"
|
380
|
+
);
|
381
|
+
}
|
382
|
+
});
|
383
|
+
|
384
|
+
it("dec should be round properly", () => {
|
163
385
|
const tests: {
|
164
386
|
d1: Dec;
|
165
387
|
exp: Int;
|
@@ -202,12 +424,22 @@ describe("Test decimals", () => {
|
|
202
424
|
const resNeg = test.d1.neg().round();
|
203
425
|
expect(resNeg.toString()).toBe(test.exp.neg().toString());
|
204
426
|
|
427
|
+
const resNegDec = test.d1.neg().roundDec();
|
428
|
+
expect(resNegDec.toString()).toBe(
|
429
|
+
test.exp.neg().toString() + ".000000000000000000"
|
430
|
+
);
|
431
|
+
|
205
432
|
const resPos = test.d1.round();
|
206
433
|
expect(resPos.toString()).toBe(test.exp.toString());
|
434
|
+
|
435
|
+
const resPosDec = test.d1.roundDec();
|
436
|
+
expect(resPosDec.toString()).toBe(
|
437
|
+
test.exp.toString() + ".000000000000000000"
|
438
|
+
);
|
207
439
|
}
|
208
440
|
});
|
209
441
|
|
210
|
-
it("dec should be
|
442
|
+
it("dec should be truncated properly", () => {
|
211
443
|
const tests: {
|
212
444
|
d1: Dec;
|
213
445
|
exp: Int;
|
@@ -250,8 +482,18 @@ describe("Test decimals", () => {
|
|
250
482
|
const resNeg = test.d1.neg().truncate();
|
251
483
|
expect(resNeg.toString()).toBe(test.exp.neg().toString());
|
252
484
|
|
485
|
+
const resNegDec = test.d1.neg().truncateDec();
|
486
|
+
expect(resNegDec.toString()).toBe(
|
487
|
+
test.exp.neg().toString() + ".000000000000000000"
|
488
|
+
);
|
489
|
+
|
253
490
|
const resPos = test.d1.truncate();
|
254
491
|
expect(resPos.toString()).toBe(test.exp.toString());
|
492
|
+
|
493
|
+
const resPosDec = test.d1.truncateDec();
|
494
|
+
expect(resPosDec.toString()).toBe(
|
495
|
+
test.exp.toString() + ".000000000000000000"
|
496
|
+
);
|
255
497
|
}
|
256
498
|
});
|
257
499
|
|
@@ -281,6 +523,11 @@ describe("Test decimals", () => {
|
|
281
523
|
precision: 5,
|
282
524
|
exp: "1.00000",
|
283
525
|
},
|
526
|
+
{
|
527
|
+
d1: new Dec(new Int("1")),
|
528
|
+
precision: 5,
|
529
|
+
exp: "1.00000",
|
530
|
+
},
|
284
531
|
{
|
285
532
|
d1: new Dec("7.5"),
|
286
533
|
precision: 3,
|
@@ -291,6 +538,11 @@ describe("Test decimals", () => {
|
|
291
538
|
precision: 0,
|
292
539
|
exp: "100",
|
293
540
|
},
|
541
|
+
{
|
542
|
+
d1: new Dec(100.000000001),
|
543
|
+
precision: 0,
|
544
|
+
exp: "100",
|
545
|
+
},
|
294
546
|
{
|
295
547
|
d1: new Dec("-0.25"),
|
296
548
|
precision: 0,
|
@@ -311,16 +563,31 @@ describe("Test decimals", () => {
|
|
311
563
|
precision: 5,
|
312
564
|
exp: "-1.00000",
|
313
565
|
},
|
566
|
+
{
|
567
|
+
d1: new Dec(-1),
|
568
|
+
precision: 5,
|
569
|
+
exp: "-1.00000",
|
570
|
+
},
|
314
571
|
{
|
315
572
|
d1: new Dec("-7.5"),
|
316
573
|
precision: 3,
|
317
574
|
exp: "-7.500",
|
318
575
|
},
|
576
|
+
{
|
577
|
+
d1: new Dec(-7.5),
|
578
|
+
precision: 3,
|
579
|
+
exp: "-7.500",
|
580
|
+
},
|
319
581
|
{
|
320
582
|
d1: new Dec("-100.000000001"),
|
321
583
|
precision: 0,
|
322
584
|
exp: "-100",
|
323
585
|
},
|
586
|
+
{
|
587
|
+
d1: new Dec(-100.000000001),
|
588
|
+
precision: 0,
|
589
|
+
exp: "-100",
|
590
|
+
},
|
324
591
|
];
|
325
592
|
|
326
593
|
for (const test of tests) {
|
@@ -328,4 +595,95 @@ describe("Test decimals", () => {
|
|
328
595
|
expect(res).toBe(test.exp);
|
329
596
|
}
|
330
597
|
});
|
598
|
+
|
599
|
+
it("Test case that input decimals exceeds 18", () => {
|
600
|
+
const tests: {
|
601
|
+
input: number | string;
|
602
|
+
res: Dec;
|
603
|
+
resStr: string;
|
604
|
+
}[] = [
|
605
|
+
{
|
606
|
+
input: "0.489234893284938249348923849283408",
|
607
|
+
res: new Dec("0.489234893284938249"),
|
608
|
+
resStr: "0.489234893284938249",
|
609
|
+
},
|
610
|
+
{
|
611
|
+
input: 0.0000010000000249348,
|
612
|
+
res: new Dec("0.000001000000024934"),
|
613
|
+
resStr: "0.000001000000024934",
|
614
|
+
},
|
615
|
+
{
|
616
|
+
input: "0.0000000000000000001",
|
617
|
+
res: new Dec("0"),
|
618
|
+
resStr: "0.000000000000000000",
|
619
|
+
},
|
620
|
+
{
|
621
|
+
input: 0.0000000000000000001,
|
622
|
+
res: new Dec("0"),
|
623
|
+
resStr: "0.000000000000000000",
|
624
|
+
},
|
625
|
+
];
|
626
|
+
|
627
|
+
for (const test of tests) {
|
628
|
+
const dec = new Dec(test.input);
|
629
|
+
|
630
|
+
expect(dec.equals(test.res)).toBe(true);
|
631
|
+
expect(dec.toString()).toBe(test.resStr);
|
632
|
+
}
|
633
|
+
});
|
634
|
+
|
635
|
+
it("Test Int/Uint from exponent number", () => {
|
636
|
+
const tests: {
|
637
|
+
num: number;
|
638
|
+
str: string;
|
639
|
+
expect: Dec;
|
640
|
+
}[] = [
|
641
|
+
{
|
642
|
+
num: 12345678901234567890123,
|
643
|
+
str: "1.2345678901234568e+22",
|
644
|
+
expect: new Dec("12345678901234568000000"),
|
645
|
+
},
|
646
|
+
{
|
647
|
+
num: -12345678901234567890123,
|
648
|
+
str: "-1.2345678901234568e+22",
|
649
|
+
expect: new Dec("-12345678901234568000000"),
|
650
|
+
},
|
651
|
+
{
|
652
|
+
num: 0.0000000000001,
|
653
|
+
str: "1e-13",
|
654
|
+
expect: new Dec("0.0000000000001"),
|
655
|
+
},
|
656
|
+
{
|
657
|
+
num: 0.000000000000123,
|
658
|
+
str: "1.23e-13",
|
659
|
+
expect: new Dec("0.000000000000123"),
|
660
|
+
},
|
661
|
+
{
|
662
|
+
num: 0.000000000000000001,
|
663
|
+
str: "1e-18",
|
664
|
+
expect: new Dec("0.000000000000000001"),
|
665
|
+
},
|
666
|
+
{
|
667
|
+
num: 0.0000000000000000001,
|
668
|
+
str: "1e-19",
|
669
|
+
expect: new Dec("0"),
|
670
|
+
},
|
671
|
+
{
|
672
|
+
num: 0.00000000000000000123,
|
673
|
+
str: "1.23e-18",
|
674
|
+
expect: new Dec("0.000000000000000001"),
|
675
|
+
},
|
676
|
+
{
|
677
|
+
num: 0.000000000000000000123,
|
678
|
+
str: "1.23e-19",
|
679
|
+
expect: new Dec("0"),
|
680
|
+
},
|
681
|
+
];
|
682
|
+
|
683
|
+
for (const test of tests) {
|
684
|
+
expect(test.num.toString()).toBe(test.str);
|
685
|
+
|
686
|
+
expect(new Dec(test.num).equals(test.expect)).toBe(true);
|
687
|
+
}
|
688
|
+
});
|
331
689
|
});
|