Skip to content

Commit

Permalink
🔀 Merge pull request gchq#468 from rubenandre/fix-putCommasInBigNum-u…
Browse files Browse the repository at this point in the history
…tils

🐛 Fix putCommasInBigNum logic
  • Loading branch information
Lissy93 committed Feb 2, 2022
2 parents b0c493f + eb06140 commit 56866d5
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 56866d5

Please sign in to comment.