fix bugs float suffix handler

This commit is contained in:
NunoSempere 2024-06-30 09:22:04 -04:00
parent 10dbda7986
commit 079535ce6b

View File

@ -63,28 +63,26 @@ func multiplyOrPassThroughError(a float64, b float64, err error) (float64, error
func parseFloat(word string) (float64, error) {
// l = len(word) // assuming no UTF stuff
if len(word) == 0 {
switch len(word) {
case 0:
return 0, errors.New("String to be parsed into float must not be the empty string")
} else if len(word) == 1 {
return strconv.ParseFloat(word)
case 1:
return strconv.ParseFloat(word, 64)
}
n = len(word) - 1
n := len(word) - 1
f, err := strconv.ParseFloat(word[:n], 64)
switch word[n] {
case "K":
f, err := strconv.ParseFloat(word[:n], 64)
case 'K':
return multiplyOrPassThroughError(1_000, f, err)
case "M":
f, err := strconv.ParseFloat(word[:n], 64)
case 'M':
return multiplyOrPassThroughError(1_000_000, f, err)
case "B":
f, err := strconv.ParseFloat(word[:n], 64)
return multiplyOrPassThroughError(1_000_000_000, f, err)
case "T":
f, err := strconv.ParseFloat(word[:n], 64)
case 'B':
return multiplyOrPassThroughError(1_000_000_000, f, err)
case 'T':
return multiplyOrPassThroughError(1_000_000_000_000, f, err)
default:
return strconv.ParseFloat(word)
return f, err
}
}