fix: formatCredits on large numbers

This commit is contained in:
Sean Yesmunt 2019-10-15 13:56:28 -04:00
parent 582e7043b5
commit 0090f195eb
2 changed files with 12 additions and 18 deletions

14
dist/bundle.es.js vendored
View file

@ -2093,18 +2093,12 @@ 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 (Number.isNaN(actualAmount) || actualAmount === 0) return '0';
if (!amount || Number.isNaN(actualAmount) || actualAmount === 0) return '0';
if (actualAmount >= 1000000) {
if (precision <= 7) {
@ -2126,7 +2120,11 @@ function formatCredits(amount, precision, shortFormat = false) {
}
}
return numberWithCommas(actualAmount.toFixed(actualPrecision >= 0 ? actualPrecision : 1).replace(/\.*0+$/, '')) + suffix;
const number = actualAmount.toString().replace(/\.*0+$/, '');
return new Intl.NumberFormat('en-IN', {
maximumSignificantDigits: actualPrecision >= 0 ? actualPrecision : 1
}).format(number) + suffix;
}
function formatFullPrice(amount, precision = 1) {

View file

@ -1,15 +1,9 @@
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 (Number.isNaN(actualAmount) || actualAmount === 0) return '0';
if (!amount || Number.isNaN(actualAmount) || actualAmount === 0) return '0';
if (actualAmount >= 1000000) {
if (precision <= 7) {
@ -31,10 +25,12 @@ export function formatCredits(amount, precision, shortFormat = false) {
}
}
const number = actualAmount.toString().replace(/\.*0+$/, '');
return (
numberWithCommas(
actualAmount.toFixed(actualPrecision >= 0 ? actualPrecision : 1).replace(/\.*0+$/, '')
) + suffix
new Intl.NumberFormat('en-IN', {
maximumSignificantDigits: actualPrecision >= 0 ? actualPrecision : 1,
}).format(number) + suffix
);
}