prun-trade-bot-go/lib/helpers/conv.go

24 lines
430 B
Go
Raw Permalink Normal View History

2024-07-17 14:56:53 +02:00
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
}