fix bugs float suffix handler
This commit is contained in:
parent
10dbda7986
commit
079535ce6b
|
@ -63,28 +63,26 @@ func multiplyOrPassThroughError(a float64, b float64, err error) (float64, error
|
||||||
func parseFloat(word string) (float64, error) {
|
func parseFloat(word string) (float64, error) {
|
||||||
// l = len(word) // assuming no UTF stuff
|
// 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")
|
return 0, errors.New("String to be parsed into float must not be the empty string")
|
||||||
} else if len(word) == 1 {
|
case 1:
|
||||||
return strconv.ParseFloat(word)
|
return strconv.ParseFloat(word, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
n = len(word) - 1
|
n := len(word) - 1
|
||||||
|
f, err := strconv.ParseFloat(word[:n], 64)
|
||||||
switch word[n] {
|
switch word[n] {
|
||||||
case "K":
|
case 'K':
|
||||||
f, err := strconv.ParseFloat(word[:n], 64)
|
|
||||||
return multiplyOrPassThroughError(1_000, f, err)
|
return multiplyOrPassThroughError(1_000, f, err)
|
||||||
case "M":
|
case 'M':
|
||||||
f, err := strconv.ParseFloat(word[:n], 64)
|
|
||||||
return multiplyOrPassThroughError(1_000_000, f, err)
|
return multiplyOrPassThroughError(1_000_000, f, err)
|
||||||
case "B":
|
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)
|
|
||||||
return multiplyOrPassThroughError(1_000_000_000, f, err)
|
return multiplyOrPassThroughError(1_000_000_000, f, err)
|
||||||
|
case 'T':
|
||||||
|
return multiplyOrPassThroughError(1_000_000_000_000, f, err)
|
||||||
default:
|
default:
|
||||||
return strconv.ParseFloat(word)
|
return f, err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user