🔀 Merge pull request #468 from rubenandre/fix-putCommasInBigNum-utils

🐛 Fix putCommasInBigNum logic
This commit is contained in:
Alicia Sykes 2022-02-02 22:12:39 +00:00 committed by GitHub
commit 56866d5a31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -75,7 +75,8 @@ export const getPlaceUrl = (placeName) => {
/* Given a large number, will add commas to make more readable */
export const putCommasInBigNum = (bigNum) => {
const strNum = Number.isNaN(bigNum) ? bigNum : String(bigNum);
return strNum.replace(/\B(?=(?:\d{3})+(?!\d))/g, ',');
const [integerPart, decimalPart] = strNum.split('.');
return integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',') + (decimalPart ? `.${decimalPart}` : '');
};
/* Given a large number, will convert 1000 into k for readability */