@utiliread/primitives 1.0.0-93 → 1.0.0-95
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/dist/cjs/breakdown-rule.js +58 -0
- package/dist/cjs/breakdown-rule.js.map +1 -0
- package/dist/cjs/breakdown-rule.spec.js +41 -0
- package/dist/cjs/breakdown-rule.spec.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/measures/pressure.js +2 -2
- package/dist/cjs/measures/pressure.js.map +1 -1
- package/dist/cjs/number-formatter.spec.js +1 -1
- package/dist/cjs/number-formatter.spec.js.map +1 -1
- package/dist/cjs/precision-number.spec.js +1 -1
- package/dist/cjs/precision-number.spec.js.map +1 -1
- package/dist/cjs/register-convention.spec.js +1 -1
- package/dist/cjs/register-convention.spec.js.map +1 -1
- package/dist/cjs/register-library.spec.js +1 -1
- package/dist/cjs/register-library.spec.js.map +1 -1
- package/dist/cjs/repository.spec.js +1 -1
- package/dist/cjs/repository.spec.js.map +1 -1
- package/dist/cjs/step.spec.js +1 -1
- package/dist/cjs/step.spec.js.map +1 -1
- package/dist/esm/breakdown-rule.d.ts +20 -0
- package/dist/esm/breakdown-rule.js +54 -0
- package/dist/esm/breakdown-rule.js.map +1 -0
- package/dist/esm/breakdown-rule.spec.d.ts +1 -0
- package/dist/esm/breakdown-rule.spec.js +39 -0
- package/dist/esm/breakdown-rule.spec.js.map +1 -0
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/measures/pressure.js +2 -2
- package/dist/esm/measures/pressure.js.map +1 -1
- package/dist/esm/number-formatter.spec.js +1 -1
- package/dist/esm/number-formatter.spec.js.map +1 -1
- package/dist/esm/precision-number.spec.js +1 -1
- package/dist/esm/precision-number.spec.js.map +1 -1
- package/dist/esm/register-convention.spec.js +1 -1
- package/dist/esm/register-convention.spec.js.map +1 -1
- package/dist/esm/register-library.spec.js +1 -1
- package/dist/esm/register-library.spec.js.map +1 -1
- package/dist/esm/repository.spec.js +1 -1
- package/dist/esm/repository.spec.js.map +1 -1
- package/dist/esm/step.spec.js +1 -1
- package/dist/esm/step.spec.js.map +1 -1
- package/locales/da/aggregates.json +13 -3
- package/locales/da/units.json +18 -0
- package/locales/en/aggregates.json +13 -3
- package/locales/en/units.json +18 -0
- package/package.json +3 -2
- package/src/breakdown-rule.spec.ts +44 -0
- package/src/breakdown-rule.ts +75 -0
- package/src/index.ts +9 -6
- package/src/measures/pressure.ts +2 -2
- package/src/number-formatter.spec.ts +549 -549
- package/src/precision-number.spec.ts +28 -28
- package/src/register-convention.spec.ts +52 -52
- package/src/register-library.spec.ts +41 -41
- package/src/repository.spec.ts +20 -20
- package/src/step.spec.ts +37 -37
- package/tsconfig.cjs.json +1 -0
- package/tsconfig.json +1 -1
|
@@ -1,549 +1,549 @@
|
|
|
1
|
-
import {
|
|
2
|
-
NumberFormatter,
|
|
3
|
-
Parts,
|
|
4
|
-
invariantDecimalSeparator,
|
|
5
|
-
localeDecimalSeparator,
|
|
6
|
-
} from "./number-formatter";
|
|
7
|
-
|
|
8
|
-
import { expect } from "
|
|
9
|
-
|
|
10
|
-
describe("toParts and toPrecision", () => {
|
|
11
|
-
it("should format correctly", () => {
|
|
12
|
-
const data: [number, number, Parts][] = [
|
|
13
|
-
[
|
|
14
|
-
0,
|
|
15
|
-
0,
|
|
16
|
-
{
|
|
17
|
-
invariantPrecisionString: "0",
|
|
18
|
-
invariantCoefficientString: "0",
|
|
19
|
-
exponent: 0,
|
|
20
|
-
noOfCoefficientDecimals: 0,
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
[
|
|
24
|
-
0.0,
|
|
25
|
-
1,
|
|
26
|
-
{
|
|
27
|
-
invariantPrecisionString: "0.0",
|
|
28
|
-
invariantCoefficientString: "0.0",
|
|
29
|
-
exponent: 0,
|
|
30
|
-
noOfCoefficientDecimals: 1,
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
[
|
|
34
|
-
77.1274,
|
|
35
|
-
1,
|
|
36
|
-
{
|
|
37
|
-
invariantPrecisionString: "8e+1",
|
|
38
|
-
invariantCoefficientString: "8",
|
|
39
|
-
exponent: 1,
|
|
40
|
-
noOfCoefficientDecimals: 0,
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
[
|
|
44
|
-
77.1274,
|
|
45
|
-
2,
|
|
46
|
-
{
|
|
47
|
-
invariantPrecisionString: "77",
|
|
48
|
-
invariantCoefficientString: "77",
|
|
49
|
-
exponent: 0,
|
|
50
|
-
noOfCoefficientDecimals: 0,
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
[
|
|
54
|
-
77.1274,
|
|
55
|
-
4,
|
|
56
|
-
{
|
|
57
|
-
invariantPrecisionString: "77.13",
|
|
58
|
-
invariantCoefficientString: "77.13",
|
|
59
|
-
exponent: 0,
|
|
60
|
-
noOfCoefficientDecimals: 2,
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
[
|
|
64
|
-
77.1274,
|
|
65
|
-
5,
|
|
66
|
-
{
|
|
67
|
-
invariantPrecisionString: "77.127",
|
|
68
|
-
invariantCoefficientString: "77.127",
|
|
69
|
-
exponent: 0,
|
|
70
|
-
noOfCoefficientDecimals: 3,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
[
|
|
74
|
-
77.1274,
|
|
75
|
-
6,
|
|
76
|
-
{
|
|
77
|
-
invariantPrecisionString: "77.1274",
|
|
78
|
-
invariantCoefficientString: "77.1274",
|
|
79
|
-
exponent: 0,
|
|
80
|
-
noOfCoefficientDecimals: 4,
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
[
|
|
84
|
-
77.1274,
|
|
85
|
-
7,
|
|
86
|
-
{
|
|
87
|
-
invariantPrecisionString: "77.12740",
|
|
88
|
-
invariantCoefficientString: "77.12740",
|
|
89
|
-
exponent: 0,
|
|
90
|
-
noOfCoefficientDecimals: 5,
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
[
|
|
94
|
-
77.1274,
|
|
95
|
-
15,
|
|
96
|
-
{
|
|
97
|
-
invariantPrecisionString: "77.1274000000000",
|
|
98
|
-
invariantCoefficientString: "77.1274000000000",
|
|
99
|
-
exponent: 0,
|
|
100
|
-
noOfCoefficientDecimals: 13,
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
[
|
|
104
|
-
77.1274,
|
|
105
|
-
16,
|
|
106
|
-
{
|
|
107
|
-
invariantPrecisionString: "77.12739999999999",
|
|
108
|
-
invariantCoefficientString: "77.12739999999999",
|
|
109
|
-
exponent: 0,
|
|
110
|
-
noOfCoefficientDecimals: 14,
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
[
|
|
114
|
-
77.1274,
|
|
115
|
-
17,
|
|
116
|
-
{
|
|
117
|
-
invariantPrecisionString: "77.127399999999994",
|
|
118
|
-
invariantCoefficientString: "77.127399999999994",
|
|
119
|
-
exponent: 0,
|
|
120
|
-
noOfCoefficientDecimals: 15,
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
[
|
|
124
|
-
77.1274,
|
|
125
|
-
18,
|
|
126
|
-
{
|
|
127
|
-
invariantPrecisionString: "77.1273999999999944",
|
|
128
|
-
invariantCoefficientString: "77.1273999999999944",
|
|
129
|
-
exponent: 0,
|
|
130
|
-
noOfCoefficientDecimals: 16,
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
[
|
|
134
|
-
77.1274,
|
|
135
|
-
19,
|
|
136
|
-
{
|
|
137
|
-
invariantPrecisionString: "77.12739999999999441",
|
|
138
|
-
invariantCoefficientString: "77.12739999999999441",
|
|
139
|
-
exponent: 0,
|
|
140
|
-
noOfCoefficientDecimals: 17,
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
[
|
|
144
|
-
77.1274,
|
|
145
|
-
20,
|
|
146
|
-
{
|
|
147
|
-
invariantPrecisionString: "77.127399999999994407",
|
|
148
|
-
invariantCoefficientString: "77.127399999999994407",
|
|
149
|
-
exponent: 0,
|
|
150
|
-
noOfCoefficientDecimals: 18,
|
|
151
|
-
},
|
|
152
|
-
],
|
|
153
|
-
[
|
|
154
|
-
77.1274,
|
|
155
|
-
21,
|
|
156
|
-
{
|
|
157
|
-
invariantPrecisionString: "77.1273999999999944066",
|
|
158
|
-
invariantCoefficientString: "77.1273999999999944066",
|
|
159
|
-
exponent: 0,
|
|
160
|
-
noOfCoefficientDecimals: 19,
|
|
161
|
-
},
|
|
162
|
-
],
|
|
163
|
-
[
|
|
164
|
-
0.00000123,
|
|
165
|
-
2,
|
|
166
|
-
{
|
|
167
|
-
invariantPrecisionString: "0.0000012",
|
|
168
|
-
invariantCoefficientString: "0.0000012",
|
|
169
|
-
exponent: 0,
|
|
170
|
-
noOfCoefficientDecimals: 7,
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
[
|
|
174
|
-
0.000000123,
|
|
175
|
-
2,
|
|
176
|
-
{
|
|
177
|
-
invariantPrecisionString: "1.2e-7",
|
|
178
|
-
invariantCoefficientString: "1.2",
|
|
179
|
-
exponent: -7,
|
|
180
|
-
noOfCoefficientDecimals: 1,
|
|
181
|
-
},
|
|
182
|
-
],
|
|
183
|
-
[
|
|
184
|
-
0.00000123,
|
|
185
|
-
21,
|
|
186
|
-
{
|
|
187
|
-
invariantPrecisionString: "0.00000123000000000000008198",
|
|
188
|
-
invariantCoefficientString: "0.00000123000000000000008198",
|
|
189
|
-
exponent: 0,
|
|
190
|
-
noOfCoefficientDecimals: 26,
|
|
191
|
-
},
|
|
192
|
-
],
|
|
193
|
-
[
|
|
194
|
-
123456,
|
|
195
|
-
3,
|
|
196
|
-
{
|
|
197
|
-
invariantPrecisionString: "1.23e+5",
|
|
198
|
-
invariantCoefficientString: "1.23",
|
|
199
|
-
exponent: 5,
|
|
200
|
-
noOfCoefficientDecimals: 2,
|
|
201
|
-
},
|
|
202
|
-
],
|
|
203
|
-
[
|
|
204
|
-
Number.MAX_VALUE,
|
|
205
|
-
3,
|
|
206
|
-
{
|
|
207
|
-
invariantPrecisionString: "1.80e+308",
|
|
208
|
-
invariantCoefficientString: "1.80",
|
|
209
|
-
exponent: 308,
|
|
210
|
-
noOfCoefficientDecimals: 2,
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
[
|
|
214
|
-
123456,
|
|
215
|
-
15,
|
|
216
|
-
{
|
|
217
|
-
invariantPrecisionString: "123456.000000000",
|
|
218
|
-
invariantCoefficientString: "123456.000000000",
|
|
219
|
-
exponent: 0,
|
|
220
|
-
noOfCoefficientDecimals: 9,
|
|
221
|
-
},
|
|
222
|
-
],
|
|
223
|
-
[
|
|
224
|
-
0,
|
|
225
|
-
5,
|
|
226
|
-
{
|
|
227
|
-
invariantPrecisionString: "0.00000",
|
|
228
|
-
invariantCoefficientString: "0.00000",
|
|
229
|
-
exponent: 0,
|
|
230
|
-
noOfCoefficientDecimals: 5,
|
|
231
|
-
},
|
|
232
|
-
],
|
|
233
|
-
[
|
|
234
|
-
0.000001,
|
|
235
|
-
1,
|
|
236
|
-
{
|
|
237
|
-
invariantPrecisionString: "0.000001",
|
|
238
|
-
invariantCoefficientString: "0.000001",
|
|
239
|
-
exponent: 0,
|
|
240
|
-
noOfCoefficientDecimals: 6,
|
|
241
|
-
},
|
|
242
|
-
],
|
|
243
|
-
[
|
|
244
|
-
0.000001,
|
|
245
|
-
10,
|
|
246
|
-
{
|
|
247
|
-
invariantPrecisionString: "0.000001000000000",
|
|
248
|
-
invariantCoefficientString: "0.000001000000000",
|
|
249
|
-
exponent: 0,
|
|
250
|
-
noOfCoefficientDecimals: 15,
|
|
251
|
-
},
|
|
252
|
-
],
|
|
253
|
-
[
|
|
254
|
-
0.0000001,
|
|
255
|
-
10,
|
|
256
|
-
{
|
|
257
|
-
invariantPrecisionString: "1.000000000e-7",
|
|
258
|
-
invariantCoefficientString: "1.000000000",
|
|
259
|
-
exponent: -7,
|
|
260
|
-
noOfCoefficientDecimals: 9,
|
|
261
|
-
},
|
|
262
|
-
],
|
|
263
|
-
[
|
|
264
|
-
0.00000000001,
|
|
265
|
-
1,
|
|
266
|
-
{
|
|
267
|
-
invariantPrecisionString: "1e-11",
|
|
268
|
-
invariantCoefficientString: "1",
|
|
269
|
-
exponent: -11,
|
|
270
|
-
noOfCoefficientDecimals: 0,
|
|
271
|
-
},
|
|
272
|
-
],
|
|
273
|
-
[
|
|
274
|
-
0.00000000001,
|
|
275
|
-
2,
|
|
276
|
-
{
|
|
277
|
-
invariantPrecisionString: "1.0e-11",
|
|
278
|
-
invariantCoefficientString: "1.0",
|
|
279
|
-
exponent: -11,
|
|
280
|
-
noOfCoefficientDecimals: 1,
|
|
281
|
-
},
|
|
282
|
-
],
|
|
283
|
-
[
|
|
284
|
-
55,
|
|
285
|
-
2,
|
|
286
|
-
{
|
|
287
|
-
invariantPrecisionString: "55",
|
|
288
|
-
invariantCoefficientString: "55",
|
|
289
|
-
exponent: 0,
|
|
290
|
-
noOfCoefficientDecimals: 0,
|
|
291
|
-
},
|
|
292
|
-
],
|
|
293
|
-
[
|
|
294
|
-
55,
|
|
295
|
-
1,
|
|
296
|
-
{
|
|
297
|
-
invariantPrecisionString: "6e+1",
|
|
298
|
-
invariantCoefficientString: "6",
|
|
299
|
-
exponent: 1,
|
|
300
|
-
noOfCoefficientDecimals: 0,
|
|
301
|
-
},
|
|
302
|
-
],
|
|
303
|
-
[
|
|
304
|
-
-55,
|
|
305
|
-
2,
|
|
306
|
-
{
|
|
307
|
-
invariantPrecisionString: "-55",
|
|
308
|
-
invariantCoefficientString: "-55",
|
|
309
|
-
exponent: 0,
|
|
310
|
-
noOfCoefficientDecimals: 0,
|
|
311
|
-
},
|
|
312
|
-
],
|
|
313
|
-
[
|
|
314
|
-
-55,
|
|
315
|
-
1,
|
|
316
|
-
{
|
|
317
|
-
invariantPrecisionString: "-6e+1",
|
|
318
|
-
invariantCoefficientString: "-6",
|
|
319
|
-
exponent: 1,
|
|
320
|
-
noOfCoefficientDecimals: 0,
|
|
321
|
-
},
|
|
322
|
-
],
|
|
323
|
-
[
|
|
324
|
-
9.59,
|
|
325
|
-
1,
|
|
326
|
-
{
|
|
327
|
-
invariantPrecisionString: "1e+1",
|
|
328
|
-
invariantCoefficientString: "1",
|
|
329
|
-
exponent: 1,
|
|
330
|
-
noOfCoefficientDecimals: 0,
|
|
331
|
-
},
|
|
332
|
-
],
|
|
333
|
-
[
|
|
334
|
-
9.59,
|
|
335
|
-
2,
|
|
336
|
-
{
|
|
337
|
-
invariantPrecisionString: "10",
|
|
338
|
-
invariantCoefficientString: "10",
|
|
339
|
-
exponent: 0,
|
|
340
|
-
noOfCoefficientDecimals: 0,
|
|
341
|
-
},
|
|
342
|
-
],
|
|
343
|
-
[
|
|
344
|
-
9.95,
|
|
345
|
-
2,
|
|
346
|
-
{
|
|
347
|
-
invariantPrecisionString: "10",
|
|
348
|
-
invariantCoefficientString: "10",
|
|
349
|
-
exponent: 0,
|
|
350
|
-
noOfCoefficientDecimals: 0,
|
|
351
|
-
},
|
|
352
|
-
],
|
|
353
|
-
[
|
|
354
|
-
9.96,
|
|
355
|
-
2,
|
|
356
|
-
{
|
|
357
|
-
invariantPrecisionString: "10",
|
|
358
|
-
invariantCoefficientString: "10",
|
|
359
|
-
exponent: 0,
|
|
360
|
-
noOfCoefficientDecimals: 0,
|
|
361
|
-
},
|
|
362
|
-
],
|
|
363
|
-
[
|
|
364
|
-
-555555555555555555555,
|
|
365
|
-
1,
|
|
366
|
-
{
|
|
367
|
-
invariantPrecisionString: "-6e+20",
|
|
368
|
-
invariantCoefficientString: "-6",
|
|
369
|
-
exponent: 20,
|
|
370
|
-
noOfCoefficientDecimals: 0,
|
|
371
|
-
},
|
|
372
|
-
],
|
|
373
|
-
[
|
|
374
|
-
-5555555555555555555555,
|
|
375
|
-
1,
|
|
376
|
-
{
|
|
377
|
-
invariantPrecisionString: "-6e+21",
|
|
378
|
-
invariantCoefficientString: "-6",
|
|
379
|
-
exponent: 21,
|
|
380
|
-
noOfCoefficientDecimals: 0,
|
|
381
|
-
},
|
|
382
|
-
],
|
|
383
|
-
[
|
|
384
|
-
18014398509482012,
|
|
385
|
-
21,
|
|
386
|
-
{
|
|
387
|
-
invariantPrecisionString: "18014398509482012.0000",
|
|
388
|
-
invariantCoefficientString: "18014398509482012.0000",
|
|
389
|
-
exponent: 0,
|
|
390
|
-
noOfCoefficientDecimals: 4,
|
|
391
|
-
},
|
|
392
|
-
],
|
|
393
|
-
[
|
|
394
|
-
180143985094820121234,
|
|
395
|
-
21,
|
|
396
|
-
{
|
|
397
|
-
invariantPrecisionString: "180143985094820134912",
|
|
398
|
-
invariantCoefficientString: "180143985094820134912",
|
|
399
|
-
exponent: 0,
|
|
400
|
-
noOfCoefficientDecimals: 0,
|
|
401
|
-
},
|
|
402
|
-
],
|
|
403
|
-
[
|
|
404
|
-
0.1,
|
|
405
|
-
21,
|
|
406
|
-
{
|
|
407
|
-
invariantPrecisionString: "0.100000000000000005551",
|
|
408
|
-
invariantCoefficientString: "0.100000000000000005551",
|
|
409
|
-
exponent: 0,
|
|
410
|
-
noOfCoefficientDecimals: 21,
|
|
411
|
-
},
|
|
412
|
-
],
|
|
413
|
-
[
|
|
414
|
-
Number.EPSILON,
|
|
415
|
-
2,
|
|
416
|
-
{
|
|
417
|
-
invariantPrecisionString: "2.2e-16",
|
|
418
|
-
invariantCoefficientString: "2.2",
|
|
419
|
-
exponent: -16,
|
|
420
|
-
noOfCoefficientDecimals: 1,
|
|
421
|
-
},
|
|
422
|
-
],
|
|
423
|
-
[
|
|
424
|
-
Number.EPSILON,
|
|
425
|
-
21,
|
|
426
|
-
{
|
|
427
|
-
invariantPrecisionString: "2.22044604925031308085e-16",
|
|
428
|
-
invariantCoefficientString: "2.22044604925031308085",
|
|
429
|
-
exponent: -16,
|
|
430
|
-
noOfCoefficientDecimals: 20,
|
|
431
|
-
},
|
|
432
|
-
],
|
|
433
|
-
[
|
|
434
|
-
Number.NaN,
|
|
435
|
-
3,
|
|
436
|
-
{
|
|
437
|
-
invariantPrecisionString: "NaN",
|
|
438
|
-
invariantCoefficientString: "NaN",
|
|
439
|
-
exponent: 0,
|
|
440
|
-
noOfCoefficientDecimals: 0,
|
|
441
|
-
},
|
|
442
|
-
],
|
|
443
|
-
[
|
|
444
|
-
Number.POSITIVE_INFINITY,
|
|
445
|
-
3,
|
|
446
|
-
{
|
|
447
|
-
invariantPrecisionString: "Infinity",
|
|
448
|
-
invariantCoefficientString: "Infinity",
|
|
449
|
-
exponent: 0,
|
|
450
|
-
noOfCoefficientDecimals: 0,
|
|
451
|
-
},
|
|
452
|
-
],
|
|
453
|
-
[
|
|
454
|
-
Number.NEGATIVE_INFINITY,
|
|
455
|
-
3,
|
|
456
|
-
{
|
|
457
|
-
invariantPrecisionString: "-Infinity",
|
|
458
|
-
invariantCoefficientString: "-Infinity",
|
|
459
|
-
exponent: 0,
|
|
460
|
-
noOfCoefficientDecimals: 0,
|
|
461
|
-
},
|
|
462
|
-
],
|
|
463
|
-
[
|
|
464
|
-
164735280,
|
|
465
|
-
7,
|
|
466
|
-
{
|
|
467
|
-
invariantPrecisionString: "1.647353e+8",
|
|
468
|
-
invariantCoefficientString: "1.647353",
|
|
469
|
-
exponent: 8,
|
|
470
|
-
noOfCoefficientDecimals: 6,
|
|
471
|
-
},
|
|
472
|
-
],
|
|
473
|
-
];
|
|
474
|
-
|
|
475
|
-
for (const [value, precision, expectedParts] of data) {
|
|
476
|
-
expect(NumberFormatter.toPrecision(value, precision)).to.equal(
|
|
477
|
-
expectedParts.invariantPrecisionString,
|
|
478
|
-
);
|
|
479
|
-
|
|
480
|
-
const localePrecisionString =
|
|
481
|
-
expectedParts.invariantPrecisionString.replace(
|
|
482
|
-
invariantDecimalSeparator,
|
|
483
|
-
localeDecimalSeparator,
|
|
484
|
-
);
|
|
485
|
-
expect(
|
|
486
|
-
NumberFormatter.toLocalePrecision(value, precision),
|
|
487
|
-
).to.equal(localePrecisionString);
|
|
488
|
-
|
|
489
|
-
const parts = NumberFormatter.getParts(value, precision);
|
|
490
|
-
expect(parts.invariantPrecisionString).to.equal(
|
|
491
|
-
expectedParts.invariantPrecisionString,
|
|
492
|
-
);
|
|
493
|
-
expect(parts.invariantCoefficientString).to.equal(
|
|
494
|
-
expectedParts.invariantCoefficientString,
|
|
495
|
-
);
|
|
496
|
-
expect(parts.exponent).to.equal(expectedParts.exponent);
|
|
497
|
-
expect(parts.noOfCoefficientDecimals).to.equal(
|
|
498
|
-
expectedParts.noOfCoefficientDecimals,
|
|
499
|
-
);
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
describe("toFixed", () => {
|
|
505
|
-
it("should format correctly", () => {
|
|
506
|
-
const data: [number, number, string][] = [
|
|
507
|
-
[0, 0, "0"],
|
|
508
|
-
[0.0, 1, "0.0"],
|
|
509
|
-
[10, 1, "10"],
|
|
510
|
-
[10, 2, "10"],
|
|
511
|
-
[10, 3, "10.0"],
|
|
512
|
-
[10, 4, "10.00"],
|
|
513
|
-
[10.2, 1, "10"],
|
|
514
|
-
[10.2, 2, "10"],
|
|
515
|
-
[10.2, 3, "10.2"],
|
|
516
|
-
[10.2, 4, "10.20"],
|
|
517
|
-
[217887000000, 6, "217887000000"],
|
|
518
|
-
];
|
|
519
|
-
|
|
520
|
-
for (const [value, precision, invariantExpected] of data) {
|
|
521
|
-
expect(NumberFormatter.toFixed(value, precision)).to.equal(
|
|
522
|
-
invariantExpected,
|
|
523
|
-
);
|
|
524
|
-
|
|
525
|
-
const localeExpected = invariantExpected.replace(
|
|
526
|
-
invariantDecimalSeparator,
|
|
527
|
-
localeDecimalSeparator,
|
|
528
|
-
);
|
|
529
|
-
expect(NumberFormatter.toLocaleFixed(value, precision)).to.equal(
|
|
530
|
-
localeExpected,
|
|
531
|
-
);
|
|
532
|
-
}
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
describe("toLocaleFixed", () => {
|
|
537
|
-
it("should format correctly", () => {
|
|
538
|
-
expect(NumberFormatter.toLocaleFixed(400, 2)).to.equal("400");
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
it("should format correctly with max decimals", () => {
|
|
542
|
-
expect(NumberFormatter.toLocaleFixed(35.123456, 8, 2)).to.equal(
|
|
543
|
-
"35.12",
|
|
544
|
-
);
|
|
545
|
-
expect(NumberFormatter.toLocaleFixed(35.129999, 8, 2)).to.equal(
|
|
546
|
-
"35.13",
|
|
547
|
-
);
|
|
548
|
-
});
|
|
549
|
-
});
|
|
1
|
+
import {
|
|
2
|
+
NumberFormatter,
|
|
3
|
+
Parts,
|
|
4
|
+
invariantDecimalSeparator,
|
|
5
|
+
localeDecimalSeparator,
|
|
6
|
+
} from "./number-formatter";
|
|
7
|
+
|
|
8
|
+
import { expect } from "chai";
|
|
9
|
+
|
|
10
|
+
describe("toParts and toPrecision", () => {
|
|
11
|
+
it("should format correctly", () => {
|
|
12
|
+
const data: [number, number, Parts][] = [
|
|
13
|
+
[
|
|
14
|
+
0,
|
|
15
|
+
0,
|
|
16
|
+
{
|
|
17
|
+
invariantPrecisionString: "0",
|
|
18
|
+
invariantCoefficientString: "0",
|
|
19
|
+
exponent: 0,
|
|
20
|
+
noOfCoefficientDecimals: 0,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
0.0,
|
|
25
|
+
1,
|
|
26
|
+
{
|
|
27
|
+
invariantPrecisionString: "0.0",
|
|
28
|
+
invariantCoefficientString: "0.0",
|
|
29
|
+
exponent: 0,
|
|
30
|
+
noOfCoefficientDecimals: 1,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
77.1274,
|
|
35
|
+
1,
|
|
36
|
+
{
|
|
37
|
+
invariantPrecisionString: "8e+1",
|
|
38
|
+
invariantCoefficientString: "8",
|
|
39
|
+
exponent: 1,
|
|
40
|
+
noOfCoefficientDecimals: 0,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
77.1274,
|
|
45
|
+
2,
|
|
46
|
+
{
|
|
47
|
+
invariantPrecisionString: "77",
|
|
48
|
+
invariantCoefficientString: "77",
|
|
49
|
+
exponent: 0,
|
|
50
|
+
noOfCoefficientDecimals: 0,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
77.1274,
|
|
55
|
+
4,
|
|
56
|
+
{
|
|
57
|
+
invariantPrecisionString: "77.13",
|
|
58
|
+
invariantCoefficientString: "77.13",
|
|
59
|
+
exponent: 0,
|
|
60
|
+
noOfCoefficientDecimals: 2,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
77.1274,
|
|
65
|
+
5,
|
|
66
|
+
{
|
|
67
|
+
invariantPrecisionString: "77.127",
|
|
68
|
+
invariantCoefficientString: "77.127",
|
|
69
|
+
exponent: 0,
|
|
70
|
+
noOfCoefficientDecimals: 3,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
77.1274,
|
|
75
|
+
6,
|
|
76
|
+
{
|
|
77
|
+
invariantPrecisionString: "77.1274",
|
|
78
|
+
invariantCoefficientString: "77.1274",
|
|
79
|
+
exponent: 0,
|
|
80
|
+
noOfCoefficientDecimals: 4,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
77.1274,
|
|
85
|
+
7,
|
|
86
|
+
{
|
|
87
|
+
invariantPrecisionString: "77.12740",
|
|
88
|
+
invariantCoefficientString: "77.12740",
|
|
89
|
+
exponent: 0,
|
|
90
|
+
noOfCoefficientDecimals: 5,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
77.1274,
|
|
95
|
+
15,
|
|
96
|
+
{
|
|
97
|
+
invariantPrecisionString: "77.1274000000000",
|
|
98
|
+
invariantCoefficientString: "77.1274000000000",
|
|
99
|
+
exponent: 0,
|
|
100
|
+
noOfCoefficientDecimals: 13,
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
77.1274,
|
|
105
|
+
16,
|
|
106
|
+
{
|
|
107
|
+
invariantPrecisionString: "77.12739999999999",
|
|
108
|
+
invariantCoefficientString: "77.12739999999999",
|
|
109
|
+
exponent: 0,
|
|
110
|
+
noOfCoefficientDecimals: 14,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
77.1274,
|
|
115
|
+
17,
|
|
116
|
+
{
|
|
117
|
+
invariantPrecisionString: "77.127399999999994",
|
|
118
|
+
invariantCoefficientString: "77.127399999999994",
|
|
119
|
+
exponent: 0,
|
|
120
|
+
noOfCoefficientDecimals: 15,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
77.1274,
|
|
125
|
+
18,
|
|
126
|
+
{
|
|
127
|
+
invariantPrecisionString: "77.1273999999999944",
|
|
128
|
+
invariantCoefficientString: "77.1273999999999944",
|
|
129
|
+
exponent: 0,
|
|
130
|
+
noOfCoefficientDecimals: 16,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
77.1274,
|
|
135
|
+
19,
|
|
136
|
+
{
|
|
137
|
+
invariantPrecisionString: "77.12739999999999441",
|
|
138
|
+
invariantCoefficientString: "77.12739999999999441",
|
|
139
|
+
exponent: 0,
|
|
140
|
+
noOfCoefficientDecimals: 17,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
77.1274,
|
|
145
|
+
20,
|
|
146
|
+
{
|
|
147
|
+
invariantPrecisionString: "77.127399999999994407",
|
|
148
|
+
invariantCoefficientString: "77.127399999999994407",
|
|
149
|
+
exponent: 0,
|
|
150
|
+
noOfCoefficientDecimals: 18,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
[
|
|
154
|
+
77.1274,
|
|
155
|
+
21,
|
|
156
|
+
{
|
|
157
|
+
invariantPrecisionString: "77.1273999999999944066",
|
|
158
|
+
invariantCoefficientString: "77.1273999999999944066",
|
|
159
|
+
exponent: 0,
|
|
160
|
+
noOfCoefficientDecimals: 19,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
[
|
|
164
|
+
0.00000123,
|
|
165
|
+
2,
|
|
166
|
+
{
|
|
167
|
+
invariantPrecisionString: "0.0000012",
|
|
168
|
+
invariantCoefficientString: "0.0000012",
|
|
169
|
+
exponent: 0,
|
|
170
|
+
noOfCoefficientDecimals: 7,
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
0.000000123,
|
|
175
|
+
2,
|
|
176
|
+
{
|
|
177
|
+
invariantPrecisionString: "1.2e-7",
|
|
178
|
+
invariantCoefficientString: "1.2",
|
|
179
|
+
exponent: -7,
|
|
180
|
+
noOfCoefficientDecimals: 1,
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
[
|
|
184
|
+
0.00000123,
|
|
185
|
+
21,
|
|
186
|
+
{
|
|
187
|
+
invariantPrecisionString: "0.00000123000000000000008198",
|
|
188
|
+
invariantCoefficientString: "0.00000123000000000000008198",
|
|
189
|
+
exponent: 0,
|
|
190
|
+
noOfCoefficientDecimals: 26,
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
[
|
|
194
|
+
123456,
|
|
195
|
+
3,
|
|
196
|
+
{
|
|
197
|
+
invariantPrecisionString: "1.23e+5",
|
|
198
|
+
invariantCoefficientString: "1.23",
|
|
199
|
+
exponent: 5,
|
|
200
|
+
noOfCoefficientDecimals: 2,
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
[
|
|
204
|
+
Number.MAX_VALUE,
|
|
205
|
+
3,
|
|
206
|
+
{
|
|
207
|
+
invariantPrecisionString: "1.80e+308",
|
|
208
|
+
invariantCoefficientString: "1.80",
|
|
209
|
+
exponent: 308,
|
|
210
|
+
noOfCoefficientDecimals: 2,
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
[
|
|
214
|
+
123456,
|
|
215
|
+
15,
|
|
216
|
+
{
|
|
217
|
+
invariantPrecisionString: "123456.000000000",
|
|
218
|
+
invariantCoefficientString: "123456.000000000",
|
|
219
|
+
exponent: 0,
|
|
220
|
+
noOfCoefficientDecimals: 9,
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
[
|
|
224
|
+
0,
|
|
225
|
+
5,
|
|
226
|
+
{
|
|
227
|
+
invariantPrecisionString: "0.00000",
|
|
228
|
+
invariantCoefficientString: "0.00000",
|
|
229
|
+
exponent: 0,
|
|
230
|
+
noOfCoefficientDecimals: 5,
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
[
|
|
234
|
+
0.000001,
|
|
235
|
+
1,
|
|
236
|
+
{
|
|
237
|
+
invariantPrecisionString: "0.000001",
|
|
238
|
+
invariantCoefficientString: "0.000001",
|
|
239
|
+
exponent: 0,
|
|
240
|
+
noOfCoefficientDecimals: 6,
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
[
|
|
244
|
+
0.000001,
|
|
245
|
+
10,
|
|
246
|
+
{
|
|
247
|
+
invariantPrecisionString: "0.000001000000000",
|
|
248
|
+
invariantCoefficientString: "0.000001000000000",
|
|
249
|
+
exponent: 0,
|
|
250
|
+
noOfCoefficientDecimals: 15,
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
[
|
|
254
|
+
0.0000001,
|
|
255
|
+
10,
|
|
256
|
+
{
|
|
257
|
+
invariantPrecisionString: "1.000000000e-7",
|
|
258
|
+
invariantCoefficientString: "1.000000000",
|
|
259
|
+
exponent: -7,
|
|
260
|
+
noOfCoefficientDecimals: 9,
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
[
|
|
264
|
+
0.00000000001,
|
|
265
|
+
1,
|
|
266
|
+
{
|
|
267
|
+
invariantPrecisionString: "1e-11",
|
|
268
|
+
invariantCoefficientString: "1",
|
|
269
|
+
exponent: -11,
|
|
270
|
+
noOfCoefficientDecimals: 0,
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
[
|
|
274
|
+
0.00000000001,
|
|
275
|
+
2,
|
|
276
|
+
{
|
|
277
|
+
invariantPrecisionString: "1.0e-11",
|
|
278
|
+
invariantCoefficientString: "1.0",
|
|
279
|
+
exponent: -11,
|
|
280
|
+
noOfCoefficientDecimals: 1,
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
[
|
|
284
|
+
55,
|
|
285
|
+
2,
|
|
286
|
+
{
|
|
287
|
+
invariantPrecisionString: "55",
|
|
288
|
+
invariantCoefficientString: "55",
|
|
289
|
+
exponent: 0,
|
|
290
|
+
noOfCoefficientDecimals: 0,
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
[
|
|
294
|
+
55,
|
|
295
|
+
1,
|
|
296
|
+
{
|
|
297
|
+
invariantPrecisionString: "6e+1",
|
|
298
|
+
invariantCoefficientString: "6",
|
|
299
|
+
exponent: 1,
|
|
300
|
+
noOfCoefficientDecimals: 0,
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
[
|
|
304
|
+
-55,
|
|
305
|
+
2,
|
|
306
|
+
{
|
|
307
|
+
invariantPrecisionString: "-55",
|
|
308
|
+
invariantCoefficientString: "-55",
|
|
309
|
+
exponent: 0,
|
|
310
|
+
noOfCoefficientDecimals: 0,
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
[
|
|
314
|
+
-55,
|
|
315
|
+
1,
|
|
316
|
+
{
|
|
317
|
+
invariantPrecisionString: "-6e+1",
|
|
318
|
+
invariantCoefficientString: "-6",
|
|
319
|
+
exponent: 1,
|
|
320
|
+
noOfCoefficientDecimals: 0,
|
|
321
|
+
},
|
|
322
|
+
],
|
|
323
|
+
[
|
|
324
|
+
9.59,
|
|
325
|
+
1,
|
|
326
|
+
{
|
|
327
|
+
invariantPrecisionString: "1e+1",
|
|
328
|
+
invariantCoefficientString: "1",
|
|
329
|
+
exponent: 1,
|
|
330
|
+
noOfCoefficientDecimals: 0,
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
[
|
|
334
|
+
9.59,
|
|
335
|
+
2,
|
|
336
|
+
{
|
|
337
|
+
invariantPrecisionString: "10",
|
|
338
|
+
invariantCoefficientString: "10",
|
|
339
|
+
exponent: 0,
|
|
340
|
+
noOfCoefficientDecimals: 0,
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
[
|
|
344
|
+
9.95,
|
|
345
|
+
2,
|
|
346
|
+
{
|
|
347
|
+
invariantPrecisionString: "10",
|
|
348
|
+
invariantCoefficientString: "10",
|
|
349
|
+
exponent: 0,
|
|
350
|
+
noOfCoefficientDecimals: 0,
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
[
|
|
354
|
+
9.96,
|
|
355
|
+
2,
|
|
356
|
+
{
|
|
357
|
+
invariantPrecisionString: "10",
|
|
358
|
+
invariantCoefficientString: "10",
|
|
359
|
+
exponent: 0,
|
|
360
|
+
noOfCoefficientDecimals: 0,
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
[
|
|
364
|
+
-555555555555555555555,
|
|
365
|
+
1,
|
|
366
|
+
{
|
|
367
|
+
invariantPrecisionString: "-6e+20",
|
|
368
|
+
invariantCoefficientString: "-6",
|
|
369
|
+
exponent: 20,
|
|
370
|
+
noOfCoefficientDecimals: 0,
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
[
|
|
374
|
+
-5555555555555555555555,
|
|
375
|
+
1,
|
|
376
|
+
{
|
|
377
|
+
invariantPrecisionString: "-6e+21",
|
|
378
|
+
invariantCoefficientString: "-6",
|
|
379
|
+
exponent: 21,
|
|
380
|
+
noOfCoefficientDecimals: 0,
|
|
381
|
+
},
|
|
382
|
+
],
|
|
383
|
+
[
|
|
384
|
+
18014398509482012,
|
|
385
|
+
21,
|
|
386
|
+
{
|
|
387
|
+
invariantPrecisionString: "18014398509482012.0000",
|
|
388
|
+
invariantCoefficientString: "18014398509482012.0000",
|
|
389
|
+
exponent: 0,
|
|
390
|
+
noOfCoefficientDecimals: 4,
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
[
|
|
394
|
+
180143985094820121234,
|
|
395
|
+
21,
|
|
396
|
+
{
|
|
397
|
+
invariantPrecisionString: "180143985094820134912",
|
|
398
|
+
invariantCoefficientString: "180143985094820134912",
|
|
399
|
+
exponent: 0,
|
|
400
|
+
noOfCoefficientDecimals: 0,
|
|
401
|
+
},
|
|
402
|
+
],
|
|
403
|
+
[
|
|
404
|
+
0.1,
|
|
405
|
+
21,
|
|
406
|
+
{
|
|
407
|
+
invariantPrecisionString: "0.100000000000000005551",
|
|
408
|
+
invariantCoefficientString: "0.100000000000000005551",
|
|
409
|
+
exponent: 0,
|
|
410
|
+
noOfCoefficientDecimals: 21,
|
|
411
|
+
},
|
|
412
|
+
],
|
|
413
|
+
[
|
|
414
|
+
Number.EPSILON,
|
|
415
|
+
2,
|
|
416
|
+
{
|
|
417
|
+
invariantPrecisionString: "2.2e-16",
|
|
418
|
+
invariantCoefficientString: "2.2",
|
|
419
|
+
exponent: -16,
|
|
420
|
+
noOfCoefficientDecimals: 1,
|
|
421
|
+
},
|
|
422
|
+
],
|
|
423
|
+
[
|
|
424
|
+
Number.EPSILON,
|
|
425
|
+
21,
|
|
426
|
+
{
|
|
427
|
+
invariantPrecisionString: "2.22044604925031308085e-16",
|
|
428
|
+
invariantCoefficientString: "2.22044604925031308085",
|
|
429
|
+
exponent: -16,
|
|
430
|
+
noOfCoefficientDecimals: 20,
|
|
431
|
+
},
|
|
432
|
+
],
|
|
433
|
+
[
|
|
434
|
+
Number.NaN,
|
|
435
|
+
3,
|
|
436
|
+
{
|
|
437
|
+
invariantPrecisionString: "NaN",
|
|
438
|
+
invariantCoefficientString: "NaN",
|
|
439
|
+
exponent: 0,
|
|
440
|
+
noOfCoefficientDecimals: 0,
|
|
441
|
+
},
|
|
442
|
+
],
|
|
443
|
+
[
|
|
444
|
+
Number.POSITIVE_INFINITY,
|
|
445
|
+
3,
|
|
446
|
+
{
|
|
447
|
+
invariantPrecisionString: "Infinity",
|
|
448
|
+
invariantCoefficientString: "Infinity",
|
|
449
|
+
exponent: 0,
|
|
450
|
+
noOfCoefficientDecimals: 0,
|
|
451
|
+
},
|
|
452
|
+
],
|
|
453
|
+
[
|
|
454
|
+
Number.NEGATIVE_INFINITY,
|
|
455
|
+
3,
|
|
456
|
+
{
|
|
457
|
+
invariantPrecisionString: "-Infinity",
|
|
458
|
+
invariantCoefficientString: "-Infinity",
|
|
459
|
+
exponent: 0,
|
|
460
|
+
noOfCoefficientDecimals: 0,
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
[
|
|
464
|
+
164735280,
|
|
465
|
+
7,
|
|
466
|
+
{
|
|
467
|
+
invariantPrecisionString: "1.647353e+8",
|
|
468
|
+
invariantCoefficientString: "1.647353",
|
|
469
|
+
exponent: 8,
|
|
470
|
+
noOfCoefficientDecimals: 6,
|
|
471
|
+
},
|
|
472
|
+
],
|
|
473
|
+
];
|
|
474
|
+
|
|
475
|
+
for (const [value, precision, expectedParts] of data) {
|
|
476
|
+
expect(NumberFormatter.toPrecision(value, precision)).to.equal(
|
|
477
|
+
expectedParts.invariantPrecisionString,
|
|
478
|
+
);
|
|
479
|
+
|
|
480
|
+
const localePrecisionString =
|
|
481
|
+
expectedParts.invariantPrecisionString.replace(
|
|
482
|
+
invariantDecimalSeparator,
|
|
483
|
+
localeDecimalSeparator,
|
|
484
|
+
);
|
|
485
|
+
expect(
|
|
486
|
+
NumberFormatter.toLocalePrecision(value, precision),
|
|
487
|
+
).to.equal(localePrecisionString);
|
|
488
|
+
|
|
489
|
+
const parts = NumberFormatter.getParts(value, precision);
|
|
490
|
+
expect(parts.invariantPrecisionString).to.equal(
|
|
491
|
+
expectedParts.invariantPrecisionString,
|
|
492
|
+
);
|
|
493
|
+
expect(parts.invariantCoefficientString).to.equal(
|
|
494
|
+
expectedParts.invariantCoefficientString,
|
|
495
|
+
);
|
|
496
|
+
expect(parts.exponent).to.equal(expectedParts.exponent);
|
|
497
|
+
expect(parts.noOfCoefficientDecimals).to.equal(
|
|
498
|
+
expectedParts.noOfCoefficientDecimals,
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
describe("toFixed", () => {
|
|
505
|
+
it("should format correctly", () => {
|
|
506
|
+
const data: [number, number, string][] = [
|
|
507
|
+
[0, 0, "0"],
|
|
508
|
+
[0.0, 1, "0.0"],
|
|
509
|
+
[10, 1, "10"],
|
|
510
|
+
[10, 2, "10"],
|
|
511
|
+
[10, 3, "10.0"],
|
|
512
|
+
[10, 4, "10.00"],
|
|
513
|
+
[10.2, 1, "10"],
|
|
514
|
+
[10.2, 2, "10"],
|
|
515
|
+
[10.2, 3, "10.2"],
|
|
516
|
+
[10.2, 4, "10.20"],
|
|
517
|
+
[217887000000, 6, "217887000000"],
|
|
518
|
+
];
|
|
519
|
+
|
|
520
|
+
for (const [value, precision, invariantExpected] of data) {
|
|
521
|
+
expect(NumberFormatter.toFixed(value, precision)).to.equal(
|
|
522
|
+
invariantExpected,
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
const localeExpected = invariantExpected.replace(
|
|
526
|
+
invariantDecimalSeparator,
|
|
527
|
+
localeDecimalSeparator,
|
|
528
|
+
);
|
|
529
|
+
expect(NumberFormatter.toLocaleFixed(value, precision)).to.equal(
|
|
530
|
+
localeExpected,
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
describe("toLocaleFixed", () => {
|
|
537
|
+
it("should format correctly", () => {
|
|
538
|
+
expect(NumberFormatter.toLocaleFixed(400, 2)).to.equal("400");
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it("should format correctly with max decimals", () => {
|
|
542
|
+
expect(NumberFormatter.toLocaleFixed(35.123456, 8, 2)).to.equal(
|
|
543
|
+
"35.12",
|
|
544
|
+
);
|
|
545
|
+
expect(NumberFormatter.toLocaleFixed(35.129999, 8, 2)).to.equal(
|
|
546
|
+
"35.13",
|
|
547
|
+
);
|
|
548
|
+
});
|
|
549
|
+
});
|