From 9919a8150998822ca997cd23418f023d64d4a3da Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 16 Oct 2019 10:05:31 -0400 Subject: [PATCH] Revert "fix: formatCredits on large numbers" This reverts commit 0090f195eb88f4620db7d038f7b01eaa76119836. --- dist/bundle.es.js | 14 ++++++++------ src/util/format-credits.js | 16 ++++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index bc8a50a..e177391 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2093,12 +2093,18 @@ const makeSelectMyStreamUrlsForPage = (page = 1) => reselect.createSelector(sele const selectMyStreamUrlsCount = reselect.createSelector(selectMyClaimUrisWithoutChannels, channels => channels.length); +function numberWithCommas(x) { + var parts = x.toString().split('.'); + parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); + return parts.join('.'); +} + function formatCredits(amount, precision, shortFormat = false) { let actualAmount = parseFloat(amount); let actualPrecision = parseFloat(precision); let suffix = ''; - if (!amount || Number.isNaN(actualAmount) || actualAmount === 0) return '0'; + if (Number.isNaN(actualAmount) || actualAmount === 0) return '0'; if (actualAmount >= 1000000) { if (precision <= 7) { @@ -2120,11 +2126,7 @@ function formatCredits(amount, precision, shortFormat = false) { } } - const number = actualAmount.toString().replace(/\.*0+$/, ''); - - return new Intl.NumberFormat('en-IN', { - maximumSignificantDigits: actualPrecision >= 0 ? actualPrecision : 1 - }).format(number) + suffix; + return numberWithCommas(actualAmount.toFixed(actualPrecision >= 0 ? actualPrecision : 1).replace(/\.*0+$/, '')) + suffix; } function formatFullPrice(amount, precision = 1) { diff --git a/src/util/format-credits.js b/src/util/format-credits.js index bb0b1b4..a090a33 100644 --- a/src/util/format-credits.js +++ b/src/util/format-credits.js @@ -1,9 +1,15 @@ +function numberWithCommas(x) { + var parts = x.toString().split('.'); + parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); + return parts.join('.'); +} + export function formatCredits(amount, precision, shortFormat = false) { let actualAmount = parseFloat(amount); let actualPrecision = parseFloat(precision); let suffix = ''; - if (!amount || Number.isNaN(actualAmount) || actualAmount === 0) return '0'; + if (Number.isNaN(actualAmount) || actualAmount === 0) return '0'; if (actualAmount >= 1000000) { if (precision <= 7) { @@ -25,12 +31,10 @@ export function formatCredits(amount, precision, shortFormat = false) { } } - const number = actualAmount.toString().replace(/\.*0+$/, ''); - return ( - new Intl.NumberFormat('en-IN', { - maximumSignificantDigits: actualPrecision >= 0 ? actualPrecision : 1, - }).format(number) + suffix + numberWithCommas( + actualAmount.toFixed(actualPrecision >= 0 ? actualPrecision : 1).replace(/\.*0+$/, '') + ) + suffix ); }