We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4d8a007 commit b9bde73Copy full SHA for b9bde73
web/src/utils/commify.ts
@@ -1,7 +1,16 @@
1
export const commify = (value: number | bigint | string): string => {
2
const [integerPart, decimalPart] = value.toString().split(".");
3
4
- const formattedIntegerPart = integerPart.replace(/\d(?=(\d{3})+$)/g, "$&,");
+ let formattedIntegerPart = "";
5
+ let counter = 0;
6
+
7
+ for (let i = integerPart.length - 1; i >= 0; i--) {
8
+ counter++;
9
+ formattedIntegerPart = integerPart[i] + formattedIntegerPart;
10
+ if (counter % 3 === 0 && i !== 0) {
11
+ formattedIntegerPart = "," + formattedIntegerPart;
12
+ }
13
14
15
return decimalPart ? `${formattedIntegerPart}.${decimalPart}` : formattedIntegerPart;
16
};
0 commit comments