fix(package): [formatter] only group leading digits in Comma (#419)

* fix(package): [formatter] only group leading digits in Comma

* test(package): [formatter] cover Comma with exponent and suffixes
This commit is contained in:
Lee Sang Gyu authored and GitHub committed 2026-11-09 12:34:27 +08:00
1 parent 961a76b6d4
commit 0112b99cd9
2 files changed
+11 -3

No files matched your search

+5 -3
View File
@@ -32,9 +32,11 @@ func Comma[T constraints.Float | constraints.Integer | string](value T, prefixSy
numString = numString[1:]
}
index := strings.Index(numString, ".")
if index == -1 {
index = len(numString)
// Only the leading run of digits gets commas, so that an exponent ("1e+21")
// or any other suffix that ParseFloat accepts is left as it is.
index := 0
for index < len(numString) && numString[index] >= '0' && numString[index] <= '9' {
index++
}
for index > 3 {