Skip to content

Commit 5be7989

Browse files
committed
fix: sonarqube issue
1 parent adaaede commit 5be7989

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/util/numbers.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ export const formatWithSeparator = (value, separator, force = false) => {
7070
}
7171
const sep = DIGIT_GROUP_SEPARATORS[separator] ?? ''
7272
const [integer, decimal] = String(value).split('.')
73-
const grouped = integer.replaceAll(/\B(?=(\d{3})+(?!\d))/g, sep)
73+
const isNegative = integer.startsWith('-')
74+
const digits = isNegative ? integer.slice(1) : integer
75+
const groups = []
76+
for (let i = digits.length; i > 0; i -= 3) {
77+
groups.unshift(digits.slice(Math.max(0, i - 3), i))
78+
}
79+
const grouped = (isNegative ? '-' : '') + groups.join(sep)
7480
return decimal ? `${grouped}.${decimal}` : grouped
7581
}
7682

0 commit comments

Comments
 (0)