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)
| 2065 | // If key data type do not match, it will return an error. |
| 2066 | // SYS-REQ-004 |
| 2067 | func GetFloat(data []byte, keys ...string) (val float64, err error) { |
| 2068 | v, t, _, e := Get(data, keys...) |
| 2069 | |
| 2070 | if e != nil { |
| 2071 | return 0, e |
| 2072 | } |
| 2073 | |
| 2074 | if t != Number { |
| 2075 | if t == Null { |
| 2076 | return 0, NullValueError |
| 2077 | } |
| 2078 | return 0, fmt.Errorf("Value is not a number: %s", string(v)) |
| 2079 | } |
| 2080 | |
| 2081 | return ParseFloat(v) |
| 2082 | } |
| 2083 | |
| 2084 | // GetInt returns the value retrieved by `Get`, cast to a int64 if possible. |
| 2085 | // If key data type do not match, it will return an error. |