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)
| 1952 | // If key data type do not match, it will return an error. |
| 1953 | // SYS-REQ-004 |
| 1954 | func GetFloat(data []byte, keys ...string) (val float64, err error) { |
| 1955 | v, t, _, e := Get(data, keys...) |
| 1956 | |
| 1957 | if e != nil { |
| 1958 | return 0, e |
| 1959 | } |
| 1960 | |
| 1961 | if t != Number { |
| 1962 | if t == Null { |
| 1963 | return 0, NullValueError |
| 1964 | } |
| 1965 | return 0, fmt.Errorf("Value is not a number: %s", string(v)) |
| 1966 | } |
| 1967 | |
| 1968 | return ParseFloat(v) |
| 1969 | } |
| 1970 | |
| 1971 | // GetInt returns the value retrieved by `Get`, cast to a int64 if possible. |
| 1972 | // If key data type do not match, it will return an error. |