Skip to content

Commit

Permalink
🐛 Fix putCommasInBigNum logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenandre committed Feb 2, 2022
1 parent 0a639b0 commit eb06140
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/MiscHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit eb06140

Please sign in to comment.