You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the confgen cannot parse number string with thousands separator.
Solution
Use strings.ReplaceAll to remove thousands separators from the string.
Use strconv.ParseInt for integers and strconv.ParseFloat for floating-point numbers to convert the cleaned string to a number.
Adjust the replacement logic based on the format of the input string (e.g., commas vs. periods).
Example: Parsing Integers with Thousands Separators
package main
import (
"fmt""strconv""strings"
)
funcparseInteger(sstring) (int64, error) {
// Remove the thousands separators (commas)s=strings.ReplaceAll(s, ",", "")
// Convert the cleaned string to an integerreturnstrconv.ParseInt(s, 10, 64)
}
funcmain() {
str:="1,234,567"num, err:=parseInteger(str)
iferr!=nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Parsed integer:", num)
}
Example: Parsing Floating-Point Numbers with Thousands Separators
package main
import (
"fmt""strconv""strings"
)
funcparseFloat(sstring) (float64, error) {
// Remove the thousands separators (commas)s=strings.ReplaceAll(s, ",", "")
// Convert the cleaned string to a floatreturnstrconv.ParseFloat(s, 64)
}
funcmain() {
str:="1,234,567.89"num, err:=parseFloat(str)
iferr!=nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Parsed float:", num)
}
Handling Different Thousands Separators
If your input uses a different thousands separator (like a period), you can adjust the strings.ReplaceAll function accordingly. For example, if the input is "1.234.567,89" (common in some European countries), you would replace the periods and commas like this:
package main
import (
"fmt""strconv""strings"
)
funcparseEuropeanFloat(sstring) (float64, error) {
// Replace periods with nothing (remove thousands separators)s=strings.ReplaceAll(s, ".", "")
// Replace the comma with a period (decimal separator)s=strings.ReplaceAll(s, ",", ".")
// Convert the cleaned string to a floatreturnstrconv.ParseFloat(s, 64)
}
funcmain() {
str:="1.234.567,89"num, err:=parseEuropeanFloat(str)
iferr!=nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Parsed float:", num)
}
Package excelize fixes the incorrect build-in number format
commit excelize: fixes the incorrect build-in number format apply the result
Release excelize v2.7.0
Bug Fixes
Fix decimal number format round issue with build-in number format, resolve issue qax-os/excelize#1328, qax-os/excelize#1368 and qax-os/excelize#1373
Problem
Currently, the confgen cannot parse number string with thousands separator.
Solution
strings.ReplaceAll
to remove thousands separators from the string.strconv.ParseInt
for integers andstrconv.ParseFloat
for floating-point numbers to convert the cleaned string to a number.Example: Parsing Integers with Thousands Separators
Example: Parsing Floating-Point Numbers with Thousands Separators
Handling Different Thousands Separators
If your input uses a different thousands separator (like a period), you can adjust the
strings.ReplaceAll
function accordingly. For example, if the input is "1.234.567,89" (common in some European countries), you would replace the periods and commas like this:References
The text was updated successfully, but these errors were encountered: