mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
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:
1 parent
961a76b6d4
commit
0112b99cd9
2 files changed
+11
-3
No files matched your search
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user