@coingecko/cryptoformat 0.7.0 → 0.8.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/lib/cryptoformat.cjs.js +56 -22
- package/lib/cryptoformat.esm.js +56 -22
- package/lib/cryptoformat.umd.js +56 -22
- package/lib/index.d.ts +3 -2
- package/package.json +1 -1
package/lib/cryptoformat.cjs.js
CHANGED
|
@@ -76,8 +76,22 @@ function isCrypto(isoCode) {
|
|
|
76
76
|
return isBTCETH(isoCode) || supportedCurrencySymbols[isoCode] == null;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// Function to transform decimal trailing zeroes to exponent
|
|
80
|
+
function decimalTrailingZeroesToExponent(formattedCurrency, maximumDecimalTrailingZeroes) {
|
|
81
|
+
const decimalTrailingZeroesPattern = new RegExp(`\\.(0{${maximumDecimalTrailingZeroes + 1},})(?=[1-9]?)`);
|
|
82
|
+
|
|
83
|
+
return formattedCurrency.replace(
|
|
84
|
+
decimalTrailingZeroesPattern,
|
|
85
|
+
(match, decimalTrailingZeroes) => `.0<sub title=\"${formattedCurrency}\">${decimalTrailingZeroes.length}</sub>`,
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
79
89
|
// Function to transform the output from Intl.NumberFormat#format
|
|
80
|
-
function formatCurrencyOverride(formattedCurrency, locale = "en") {
|
|
90
|
+
function formatCurrencyOverride(formattedCurrency, locale = "en", maximumDecimalTrailingZeroes) {
|
|
91
|
+
if (typeof maximumDecimalTrailingZeroes !== "undefined") {
|
|
92
|
+
formattedCurrency = decimalTrailingZeroesToExponent(formattedCurrency, maximumDecimalTrailingZeroes);
|
|
93
|
+
}
|
|
94
|
+
|
|
81
95
|
// If currency code remains in front
|
|
82
96
|
const currencyCodeFrontMatch = formattedCurrency.match(/^[A-Z]{3}\s?/);
|
|
83
97
|
if (currencyCodeFrontMatch != null) {
|
|
@@ -281,6 +295,7 @@ function formatCurrency(
|
|
|
281
295
|
abbreviated = false,
|
|
282
296
|
) {
|
|
283
297
|
isoCode = isoCode.toUpperCase();
|
|
298
|
+
let maximumDecimalTrailingZeroes = undefined;
|
|
284
299
|
|
|
285
300
|
if (currentISOCode !== isoCode || currentLocale != locale) {
|
|
286
301
|
currentISOCode = isoCode;
|
|
@@ -314,10 +329,13 @@ function formatCurrency(
|
|
|
314
329
|
: amount;
|
|
315
330
|
// Round off to number of significant figures without trailing 0's
|
|
316
331
|
return `${parseFloat(raw_amount).toPrecision(noDecimal.significantFigures) / 1}`;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (noDecimal.hasOwnProperty("maximumDecimalTrailingZeroes")) {
|
|
335
|
+
maximumDecimalTrailingZeroes = noDecimal.maximumDecimalTrailingZeroes;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (noDecimal.hasOwnProperty("decimalPlaces") && noDecimal.hasOwnProperty("significantFigures")) {
|
|
321
339
|
// Show specified number of significant digits with cutoff of specified fraction digits
|
|
322
340
|
const currencyFormatterCustom = generateFormatter(
|
|
323
341
|
isoCode,
|
|
@@ -330,9 +348,10 @@ function formatCurrency(
|
|
|
330
348
|
currencyFormatterCustom.format(
|
|
331
349
|
Number.parseFloat(amount.toFixed(noDecimal.decimalPlaces))
|
|
332
350
|
),
|
|
333
|
-
locale
|
|
351
|
+
locale,
|
|
352
|
+
maximumDecimalTrailingZeroes
|
|
334
353
|
);
|
|
335
|
-
} else {
|
|
354
|
+
} else if (noDecimal.hasOwnProperty("decimalPlaces") || noDecimal.hasOwnProperty("significantFigures")) {
|
|
336
355
|
const currencyFormatterCustom = generateFormatter(
|
|
337
356
|
isoCode,
|
|
338
357
|
locale,
|
|
@@ -342,7 +361,8 @@ function formatCurrency(
|
|
|
342
361
|
|
|
343
362
|
return formatCurrencyOverride(
|
|
344
363
|
currencyFormatterCustom.format(amount),
|
|
345
|
-
locale
|
|
364
|
+
locale,
|
|
365
|
+
maximumDecimalTrailingZeroes
|
|
346
366
|
);
|
|
347
367
|
}
|
|
348
368
|
}
|
|
@@ -360,7 +380,8 @@ function formatCurrency(
|
|
|
360
380
|
if (amount === 0.0) {
|
|
361
381
|
return formatCurrencyOverride(
|
|
362
382
|
currencyFormatterNormal.format(amount),
|
|
363
|
-
locale
|
|
383
|
+
locale,
|
|
384
|
+
maximumDecimalTrailingZeroes
|
|
364
385
|
);
|
|
365
386
|
} else if (price >= LARGE_CRYPTO_THRESHOLD) {
|
|
366
387
|
// Large crypto amount, show no decimal value
|
|
@@ -375,34 +396,40 @@ function formatCurrency(
|
|
|
375
396
|
// Medium crypto amount, show 3 fraction digits
|
|
376
397
|
return formatCurrencyOverride(
|
|
377
398
|
currencyFormatterMedium.format(amount),
|
|
378
|
-
locale
|
|
399
|
+
locale,
|
|
400
|
+
maximumDecimalTrailingZeroes
|
|
379
401
|
);
|
|
380
402
|
} else if (price >= 1.0 && price < MEDIUM_CRYPTO_THRESHOLD) {
|
|
381
403
|
// crypto amount, show 6 fraction digits
|
|
382
404
|
return formatCurrencyOverride(
|
|
383
405
|
currencyFormatterSmall.format(amount),
|
|
384
|
-
locale
|
|
406
|
+
locale,
|
|
407
|
+
maximumDecimalTrailingZeroes
|
|
385
408
|
);
|
|
386
409
|
} else if (price >= 0.000001 && price < 1.0) {
|
|
387
410
|
// crypto amount, show 8 fraction digits
|
|
388
411
|
return formatCurrencyOverride(
|
|
389
412
|
currencyFormatterVerySmall.format(amount),
|
|
390
|
-
locale
|
|
413
|
+
locale,
|
|
414
|
+
maximumDecimalTrailingZeroes
|
|
391
415
|
);
|
|
392
416
|
} else if (price >= 10**-9 && price < 10**-6) {
|
|
393
417
|
return formatCurrencyOverride(
|
|
394
418
|
currencyFormatterVeryVerySmall.format(amount),
|
|
395
|
-
locale
|
|
419
|
+
locale,
|
|
420
|
+
maximumDecimalTrailingZeroes
|
|
396
421
|
);
|
|
397
422
|
} else if (price >= 10**-12 && price < 10**-9) {
|
|
398
423
|
return formatCurrencyOverride(
|
|
399
424
|
currencyFormatter15DP.format(amount),
|
|
400
|
-
locale
|
|
425
|
+
locale,
|
|
426
|
+
maximumDecimalTrailingZeroes
|
|
401
427
|
);
|
|
402
428
|
} else if (price < 10**-12) {
|
|
403
429
|
return formatCurrencyOverride(
|
|
404
430
|
currencyFormatter18DP.format(amount),
|
|
405
|
-
locale
|
|
431
|
+
locale,
|
|
432
|
+
maximumDecimalTrailingZeroes
|
|
406
433
|
);
|
|
407
434
|
}
|
|
408
435
|
} else {
|
|
@@ -426,37 +453,44 @@ function formatCurrency(
|
|
|
426
453
|
if (unsigned_amount === 0.0) {
|
|
427
454
|
return formatCurrencyOverride(
|
|
428
455
|
currencyFormatterNormal.format(amount),
|
|
429
|
-
locale
|
|
456
|
+
locale,
|
|
457
|
+
maximumDecimalTrailingZeroes
|
|
430
458
|
);
|
|
431
459
|
} else if (unsigned_amount < 10**-12) {
|
|
432
460
|
return formatCurrencyOverride(
|
|
433
461
|
currencyFormatter18DP.format(amount),
|
|
434
|
-
locale
|
|
462
|
+
locale,
|
|
463
|
+
maximumDecimalTrailingZeroes
|
|
435
464
|
);
|
|
436
465
|
} else if (unsigned_amount < 10**-9) {
|
|
437
466
|
return formatCurrencyOverride(
|
|
438
467
|
currencyFormatter15DP.format(amount),
|
|
439
|
-
locale
|
|
468
|
+
locale,
|
|
469
|
+
maximumDecimalTrailingZeroes
|
|
440
470
|
);
|
|
441
471
|
} else if (unsigned_amount < 10**-6) {
|
|
442
472
|
return formatCurrencyOverride(
|
|
443
473
|
currencyFormatterVeryVerySmall.format(amount),
|
|
444
|
-
locale
|
|
474
|
+
locale,
|
|
475
|
+
maximumDecimalTrailingZeroes
|
|
445
476
|
);
|
|
446
477
|
} else if (unsigned_amount < 0.05) {
|
|
447
478
|
return formatCurrencyOverride(
|
|
448
479
|
currencyFormatterVerySmall.format(amount),
|
|
449
|
-
locale
|
|
480
|
+
locale,
|
|
481
|
+
maximumDecimalTrailingZeroes
|
|
450
482
|
);
|
|
451
483
|
} else if (unsigned_amount < 1.0) {
|
|
452
484
|
return formatCurrencyOverride(
|
|
453
485
|
currencyFormatterSmall.format(amount),
|
|
454
|
-
locale
|
|
486
|
+
locale,
|
|
487
|
+
maximumDecimalTrailingZeroes
|
|
455
488
|
);
|
|
456
489
|
} else if (isoCode === "JPY" && unsigned_amount < 100) {
|
|
457
490
|
return formatCurrencyOverride(
|
|
458
491
|
currencyFormatterTwoDecimal.format(amount),
|
|
459
|
-
locale
|
|
492
|
+
locale,
|
|
493
|
+
maximumDecimalTrailingZeroes
|
|
460
494
|
);
|
|
461
495
|
} else if (unsigned_amount > NO_DECIMAL_THRESHOLD) {
|
|
462
496
|
return formatCurrencyOverride(
|
package/lib/cryptoformat.esm.js
CHANGED
|
@@ -72,8 +72,22 @@ function isCrypto(isoCode) {
|
|
|
72
72
|
return isBTCETH(isoCode) || supportedCurrencySymbols[isoCode] == null;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
// Function to transform decimal trailing zeroes to exponent
|
|
76
|
+
function decimalTrailingZeroesToExponent(formattedCurrency, maximumDecimalTrailingZeroes) {
|
|
77
|
+
const decimalTrailingZeroesPattern = new RegExp(`\\.(0{${maximumDecimalTrailingZeroes + 1},})(?=[1-9]?)`);
|
|
78
|
+
|
|
79
|
+
return formattedCurrency.replace(
|
|
80
|
+
decimalTrailingZeroesPattern,
|
|
81
|
+
(match, decimalTrailingZeroes) => `.0<sub title=\"${formattedCurrency}\">${decimalTrailingZeroes.length}</sub>`,
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
75
85
|
// Function to transform the output from Intl.NumberFormat#format
|
|
76
|
-
function formatCurrencyOverride(formattedCurrency, locale = "en") {
|
|
86
|
+
function formatCurrencyOverride(formattedCurrency, locale = "en", maximumDecimalTrailingZeroes) {
|
|
87
|
+
if (typeof maximumDecimalTrailingZeroes !== "undefined") {
|
|
88
|
+
formattedCurrency = decimalTrailingZeroesToExponent(formattedCurrency, maximumDecimalTrailingZeroes);
|
|
89
|
+
}
|
|
90
|
+
|
|
77
91
|
// If currency code remains in front
|
|
78
92
|
const currencyCodeFrontMatch = formattedCurrency.match(/^[A-Z]{3}\s?/);
|
|
79
93
|
if (currencyCodeFrontMatch != null) {
|
|
@@ -277,6 +291,7 @@ function formatCurrency(
|
|
|
277
291
|
abbreviated = false,
|
|
278
292
|
) {
|
|
279
293
|
isoCode = isoCode.toUpperCase();
|
|
294
|
+
let maximumDecimalTrailingZeroes = undefined;
|
|
280
295
|
|
|
281
296
|
if (currentISOCode !== isoCode || currentLocale != locale) {
|
|
282
297
|
currentISOCode = isoCode;
|
|
@@ -310,10 +325,13 @@ function formatCurrency(
|
|
|
310
325
|
: amount;
|
|
311
326
|
// Round off to number of significant figures without trailing 0's
|
|
312
327
|
return `${parseFloat(raw_amount).toPrecision(noDecimal.significantFigures) / 1}`;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (noDecimal.hasOwnProperty("maximumDecimalTrailingZeroes")) {
|
|
331
|
+
maximumDecimalTrailingZeroes = noDecimal.maximumDecimalTrailingZeroes;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (noDecimal.hasOwnProperty("decimalPlaces") && noDecimal.hasOwnProperty("significantFigures")) {
|
|
317
335
|
// Show specified number of significant digits with cutoff of specified fraction digits
|
|
318
336
|
const currencyFormatterCustom = generateFormatter(
|
|
319
337
|
isoCode,
|
|
@@ -326,9 +344,10 @@ function formatCurrency(
|
|
|
326
344
|
currencyFormatterCustom.format(
|
|
327
345
|
Number.parseFloat(amount.toFixed(noDecimal.decimalPlaces))
|
|
328
346
|
),
|
|
329
|
-
locale
|
|
347
|
+
locale,
|
|
348
|
+
maximumDecimalTrailingZeroes
|
|
330
349
|
);
|
|
331
|
-
} else {
|
|
350
|
+
} else if (noDecimal.hasOwnProperty("decimalPlaces") || noDecimal.hasOwnProperty("significantFigures")) {
|
|
332
351
|
const currencyFormatterCustom = generateFormatter(
|
|
333
352
|
isoCode,
|
|
334
353
|
locale,
|
|
@@ -338,7 +357,8 @@ function formatCurrency(
|
|
|
338
357
|
|
|
339
358
|
return formatCurrencyOverride(
|
|
340
359
|
currencyFormatterCustom.format(amount),
|
|
341
|
-
locale
|
|
360
|
+
locale,
|
|
361
|
+
maximumDecimalTrailingZeroes
|
|
342
362
|
);
|
|
343
363
|
}
|
|
344
364
|
}
|
|
@@ -356,7 +376,8 @@ function formatCurrency(
|
|
|
356
376
|
if (amount === 0.0) {
|
|
357
377
|
return formatCurrencyOverride(
|
|
358
378
|
currencyFormatterNormal.format(amount),
|
|
359
|
-
locale
|
|
379
|
+
locale,
|
|
380
|
+
maximumDecimalTrailingZeroes
|
|
360
381
|
);
|
|
361
382
|
} else if (price >= LARGE_CRYPTO_THRESHOLD) {
|
|
362
383
|
// Large crypto amount, show no decimal value
|
|
@@ -371,34 +392,40 @@ function formatCurrency(
|
|
|
371
392
|
// Medium crypto amount, show 3 fraction digits
|
|
372
393
|
return formatCurrencyOverride(
|
|
373
394
|
currencyFormatterMedium.format(amount),
|
|
374
|
-
locale
|
|
395
|
+
locale,
|
|
396
|
+
maximumDecimalTrailingZeroes
|
|
375
397
|
);
|
|
376
398
|
} else if (price >= 1.0 && price < MEDIUM_CRYPTO_THRESHOLD) {
|
|
377
399
|
// crypto amount, show 6 fraction digits
|
|
378
400
|
return formatCurrencyOverride(
|
|
379
401
|
currencyFormatterSmall.format(amount),
|
|
380
|
-
locale
|
|
402
|
+
locale,
|
|
403
|
+
maximumDecimalTrailingZeroes
|
|
381
404
|
);
|
|
382
405
|
} else if (price >= 0.000001 && price < 1.0) {
|
|
383
406
|
// crypto amount, show 8 fraction digits
|
|
384
407
|
return formatCurrencyOverride(
|
|
385
408
|
currencyFormatterVerySmall.format(amount),
|
|
386
|
-
locale
|
|
409
|
+
locale,
|
|
410
|
+
maximumDecimalTrailingZeroes
|
|
387
411
|
);
|
|
388
412
|
} else if (price >= 10**-9 && price < 10**-6) {
|
|
389
413
|
return formatCurrencyOverride(
|
|
390
414
|
currencyFormatterVeryVerySmall.format(amount),
|
|
391
|
-
locale
|
|
415
|
+
locale,
|
|
416
|
+
maximumDecimalTrailingZeroes
|
|
392
417
|
);
|
|
393
418
|
} else if (price >= 10**-12 && price < 10**-9) {
|
|
394
419
|
return formatCurrencyOverride(
|
|
395
420
|
currencyFormatter15DP.format(amount),
|
|
396
|
-
locale
|
|
421
|
+
locale,
|
|
422
|
+
maximumDecimalTrailingZeroes
|
|
397
423
|
);
|
|
398
424
|
} else if (price < 10**-12) {
|
|
399
425
|
return formatCurrencyOverride(
|
|
400
426
|
currencyFormatter18DP.format(amount),
|
|
401
|
-
locale
|
|
427
|
+
locale,
|
|
428
|
+
maximumDecimalTrailingZeroes
|
|
402
429
|
);
|
|
403
430
|
}
|
|
404
431
|
} else {
|
|
@@ -422,37 +449,44 @@ function formatCurrency(
|
|
|
422
449
|
if (unsigned_amount === 0.0) {
|
|
423
450
|
return formatCurrencyOverride(
|
|
424
451
|
currencyFormatterNormal.format(amount),
|
|
425
|
-
locale
|
|
452
|
+
locale,
|
|
453
|
+
maximumDecimalTrailingZeroes
|
|
426
454
|
);
|
|
427
455
|
} else if (unsigned_amount < 10**-12) {
|
|
428
456
|
return formatCurrencyOverride(
|
|
429
457
|
currencyFormatter18DP.format(amount),
|
|
430
|
-
locale
|
|
458
|
+
locale,
|
|
459
|
+
maximumDecimalTrailingZeroes
|
|
431
460
|
);
|
|
432
461
|
} else if (unsigned_amount < 10**-9) {
|
|
433
462
|
return formatCurrencyOverride(
|
|
434
463
|
currencyFormatter15DP.format(amount),
|
|
435
|
-
locale
|
|
464
|
+
locale,
|
|
465
|
+
maximumDecimalTrailingZeroes
|
|
436
466
|
);
|
|
437
467
|
} else if (unsigned_amount < 10**-6) {
|
|
438
468
|
return formatCurrencyOverride(
|
|
439
469
|
currencyFormatterVeryVerySmall.format(amount),
|
|
440
|
-
locale
|
|
470
|
+
locale,
|
|
471
|
+
maximumDecimalTrailingZeroes
|
|
441
472
|
);
|
|
442
473
|
} else if (unsigned_amount < 0.05) {
|
|
443
474
|
return formatCurrencyOverride(
|
|
444
475
|
currencyFormatterVerySmall.format(amount),
|
|
445
|
-
locale
|
|
476
|
+
locale,
|
|
477
|
+
maximumDecimalTrailingZeroes
|
|
446
478
|
);
|
|
447
479
|
} else if (unsigned_amount < 1.0) {
|
|
448
480
|
return formatCurrencyOverride(
|
|
449
481
|
currencyFormatterSmall.format(amount),
|
|
450
|
-
locale
|
|
482
|
+
locale,
|
|
483
|
+
maximumDecimalTrailingZeroes
|
|
451
484
|
);
|
|
452
485
|
} else if (isoCode === "JPY" && unsigned_amount < 100) {
|
|
453
486
|
return formatCurrencyOverride(
|
|
454
487
|
currencyFormatterTwoDecimal.format(amount),
|
|
455
|
-
locale
|
|
488
|
+
locale,
|
|
489
|
+
maximumDecimalTrailingZeroes
|
|
456
490
|
);
|
|
457
491
|
} else if (unsigned_amount > NO_DECIMAL_THRESHOLD) {
|
|
458
492
|
return formatCurrencyOverride(
|
package/lib/cryptoformat.umd.js
CHANGED
|
@@ -78,8 +78,22 @@
|
|
|
78
78
|
return isBTCETH(isoCode) || supportedCurrencySymbols[isoCode] == null;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
// Function to transform decimal trailing zeroes to exponent
|
|
82
|
+
function decimalTrailingZeroesToExponent(formattedCurrency, maximumDecimalTrailingZeroes) {
|
|
83
|
+
const decimalTrailingZeroesPattern = new RegExp(`\\.(0{${maximumDecimalTrailingZeroes + 1},})(?=[1-9]?)`);
|
|
84
|
+
|
|
85
|
+
return formattedCurrency.replace(
|
|
86
|
+
decimalTrailingZeroesPattern,
|
|
87
|
+
(match, decimalTrailingZeroes) => `.0<sub title=\"${formattedCurrency}\">${decimalTrailingZeroes.length}</sub>`,
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
81
91
|
// Function to transform the output from Intl.NumberFormat#format
|
|
82
|
-
function formatCurrencyOverride(formattedCurrency, locale = "en") {
|
|
92
|
+
function formatCurrencyOverride(formattedCurrency, locale = "en", maximumDecimalTrailingZeroes) {
|
|
93
|
+
if (typeof maximumDecimalTrailingZeroes !== "undefined") {
|
|
94
|
+
formattedCurrency = decimalTrailingZeroesToExponent(formattedCurrency, maximumDecimalTrailingZeroes);
|
|
95
|
+
}
|
|
96
|
+
|
|
83
97
|
// If currency code remains in front
|
|
84
98
|
const currencyCodeFrontMatch = formattedCurrency.match(/^[A-Z]{3}\s?/);
|
|
85
99
|
if (currencyCodeFrontMatch != null) {
|
|
@@ -283,6 +297,7 @@
|
|
|
283
297
|
abbreviated = false,
|
|
284
298
|
) {
|
|
285
299
|
isoCode = isoCode.toUpperCase();
|
|
300
|
+
let maximumDecimalTrailingZeroes = undefined;
|
|
286
301
|
|
|
287
302
|
if (currentISOCode !== isoCode || currentLocale != locale) {
|
|
288
303
|
currentISOCode = isoCode;
|
|
@@ -316,10 +331,13 @@
|
|
|
316
331
|
: amount;
|
|
317
332
|
// Round off to number of significant figures without trailing 0's
|
|
318
333
|
return `${parseFloat(raw_amount).toPrecision(noDecimal.significantFigures) / 1}`;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (noDecimal.hasOwnProperty("maximumDecimalTrailingZeroes")) {
|
|
337
|
+
maximumDecimalTrailingZeroes = noDecimal.maximumDecimalTrailingZeroes;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (noDecimal.hasOwnProperty("decimalPlaces") && noDecimal.hasOwnProperty("significantFigures")) {
|
|
323
341
|
// Show specified number of significant digits with cutoff of specified fraction digits
|
|
324
342
|
const currencyFormatterCustom = generateFormatter(
|
|
325
343
|
isoCode,
|
|
@@ -332,9 +350,10 @@
|
|
|
332
350
|
currencyFormatterCustom.format(
|
|
333
351
|
Number.parseFloat(amount.toFixed(noDecimal.decimalPlaces))
|
|
334
352
|
),
|
|
335
|
-
locale
|
|
353
|
+
locale,
|
|
354
|
+
maximumDecimalTrailingZeroes
|
|
336
355
|
);
|
|
337
|
-
} else {
|
|
356
|
+
} else if (noDecimal.hasOwnProperty("decimalPlaces") || noDecimal.hasOwnProperty("significantFigures")) {
|
|
338
357
|
const currencyFormatterCustom = generateFormatter(
|
|
339
358
|
isoCode,
|
|
340
359
|
locale,
|
|
@@ -344,7 +363,8 @@
|
|
|
344
363
|
|
|
345
364
|
return formatCurrencyOverride(
|
|
346
365
|
currencyFormatterCustom.format(amount),
|
|
347
|
-
locale
|
|
366
|
+
locale,
|
|
367
|
+
maximumDecimalTrailingZeroes
|
|
348
368
|
);
|
|
349
369
|
}
|
|
350
370
|
}
|
|
@@ -362,7 +382,8 @@
|
|
|
362
382
|
if (amount === 0.0) {
|
|
363
383
|
return formatCurrencyOverride(
|
|
364
384
|
currencyFormatterNormal.format(amount),
|
|
365
|
-
locale
|
|
385
|
+
locale,
|
|
386
|
+
maximumDecimalTrailingZeroes
|
|
366
387
|
);
|
|
367
388
|
} else if (price >= LARGE_CRYPTO_THRESHOLD) {
|
|
368
389
|
// Large crypto amount, show no decimal value
|
|
@@ -377,34 +398,40 @@
|
|
|
377
398
|
// Medium crypto amount, show 3 fraction digits
|
|
378
399
|
return formatCurrencyOverride(
|
|
379
400
|
currencyFormatterMedium.format(amount),
|
|
380
|
-
locale
|
|
401
|
+
locale,
|
|
402
|
+
maximumDecimalTrailingZeroes
|
|
381
403
|
);
|
|
382
404
|
} else if (price >= 1.0 && price < MEDIUM_CRYPTO_THRESHOLD) {
|
|
383
405
|
// crypto amount, show 6 fraction digits
|
|
384
406
|
return formatCurrencyOverride(
|
|
385
407
|
currencyFormatterSmall.format(amount),
|
|
386
|
-
locale
|
|
408
|
+
locale,
|
|
409
|
+
maximumDecimalTrailingZeroes
|
|
387
410
|
);
|
|
388
411
|
} else if (price >= 0.000001 && price < 1.0) {
|
|
389
412
|
// crypto amount, show 8 fraction digits
|
|
390
413
|
return formatCurrencyOverride(
|
|
391
414
|
currencyFormatterVerySmall.format(amount),
|
|
392
|
-
locale
|
|
415
|
+
locale,
|
|
416
|
+
maximumDecimalTrailingZeroes
|
|
393
417
|
);
|
|
394
418
|
} else if (price >= 10**-9 && price < 10**-6) {
|
|
395
419
|
return formatCurrencyOverride(
|
|
396
420
|
currencyFormatterVeryVerySmall.format(amount),
|
|
397
|
-
locale
|
|
421
|
+
locale,
|
|
422
|
+
maximumDecimalTrailingZeroes
|
|
398
423
|
);
|
|
399
424
|
} else if (price >= 10**-12 && price < 10**-9) {
|
|
400
425
|
return formatCurrencyOverride(
|
|
401
426
|
currencyFormatter15DP.format(amount),
|
|
402
|
-
locale
|
|
427
|
+
locale,
|
|
428
|
+
maximumDecimalTrailingZeroes
|
|
403
429
|
);
|
|
404
430
|
} else if (price < 10**-12) {
|
|
405
431
|
return formatCurrencyOverride(
|
|
406
432
|
currencyFormatter18DP.format(amount),
|
|
407
|
-
locale
|
|
433
|
+
locale,
|
|
434
|
+
maximumDecimalTrailingZeroes
|
|
408
435
|
);
|
|
409
436
|
}
|
|
410
437
|
} else {
|
|
@@ -428,37 +455,44 @@
|
|
|
428
455
|
if (unsigned_amount === 0.0) {
|
|
429
456
|
return formatCurrencyOverride(
|
|
430
457
|
currencyFormatterNormal.format(amount),
|
|
431
|
-
locale
|
|
458
|
+
locale,
|
|
459
|
+
maximumDecimalTrailingZeroes
|
|
432
460
|
);
|
|
433
461
|
} else if (unsigned_amount < 10**-12) {
|
|
434
462
|
return formatCurrencyOverride(
|
|
435
463
|
currencyFormatter18DP.format(amount),
|
|
436
|
-
locale
|
|
464
|
+
locale,
|
|
465
|
+
maximumDecimalTrailingZeroes
|
|
437
466
|
);
|
|
438
467
|
} else if (unsigned_amount < 10**-9) {
|
|
439
468
|
return formatCurrencyOverride(
|
|
440
469
|
currencyFormatter15DP.format(amount),
|
|
441
|
-
locale
|
|
470
|
+
locale,
|
|
471
|
+
maximumDecimalTrailingZeroes
|
|
442
472
|
);
|
|
443
473
|
} else if (unsigned_amount < 10**-6) {
|
|
444
474
|
return formatCurrencyOverride(
|
|
445
475
|
currencyFormatterVeryVerySmall.format(amount),
|
|
446
|
-
locale
|
|
476
|
+
locale,
|
|
477
|
+
maximumDecimalTrailingZeroes
|
|
447
478
|
);
|
|
448
479
|
} else if (unsigned_amount < 0.05) {
|
|
449
480
|
return formatCurrencyOverride(
|
|
450
481
|
currencyFormatterVerySmall.format(amount),
|
|
451
|
-
locale
|
|
482
|
+
locale,
|
|
483
|
+
maximumDecimalTrailingZeroes
|
|
452
484
|
);
|
|
453
485
|
} else if (unsigned_amount < 1.0) {
|
|
454
486
|
return formatCurrencyOverride(
|
|
455
487
|
currencyFormatterSmall.format(amount),
|
|
456
|
-
locale
|
|
488
|
+
locale,
|
|
489
|
+
maximumDecimalTrailingZeroes
|
|
457
490
|
);
|
|
458
491
|
} else if (isoCode === "JPY" && unsigned_amount < 100) {
|
|
459
492
|
return formatCurrencyOverride(
|
|
460
493
|
currencyFormatterTwoDecimal.format(amount),
|
|
461
|
-
locale
|
|
494
|
+
locale,
|
|
495
|
+
maximumDecimalTrailingZeroes
|
|
462
496
|
);
|
|
463
497
|
} else if (unsigned_amount > NO_DECIMAL_THRESHOLD) {
|
|
464
498
|
return formatCurrencyOverride(
|
package/lib/index.d.ts
CHANGED
package/package.json
CHANGED