GetFloat returns the value retrieved by `Get`, cast to a float64 if possible. The offset is the same as in `Get`. If key data type do not match, it will return an error. SYS-REQ-004
(data []byte, keys ...string)
| 1971 | // If key data type do not match, it will return an error. |
| 1972 | // SYS-REQ-004 |
| 1973 | func GetFloat(data []byte, keys ...string) (val float64, err error) { |
| 1974 | v, t, _, e := Get(data, keys...) |
| 1975 | |
| 1976 | if e != nil { |
| 1977 | return 0, e |
| 1978 | } |
| 1979 | |
| 1980 | if t != Number { |
| 1981 | if t == Null { |
| 1982 | return 0, NullValueError |
| 1983 | } |
| 1984 | return 0, fmt.Errorf("Value is not a number: %s", string(v)) |
| 1985 | } |
| 1986 | |
| 1987 | return ParseFloat(v) |
| 1988 | } |
| 1989 | |
| 1990 | // GetInt returns the value retrieved by `Get`, cast to a int64 if possible. |
| 1991 | // If key data type do not match, it will return an error. |