24 lines
430 B
Go
24 lines
430 B
Go
package helpers
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func ParseNumericString(value string) (float64, error) {
|
|
|
|
value = strings.Replace(value, " ", "", 9999)
|
|
value = strings.Replace(value, ",", ".", 9999)
|
|
|
|
out, err := strconv.ParseFloat(value, 64)
|
|
if err != nil {
|
|
result, err := strconv.ParseInt(value, 10, 64)
|
|
out = float64(result)
|
|
if err != nil {
|
|
return 0.0, fmt.Errorf("not numeric")
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|