🐛 Fix putCommasInBigNum logic

This commit is contained in:
Ruben Silva 2022-02-02 19:34:38 +00:00
parent 0a639b0f08
commit eb06140fa4
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 */