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)
| 2011 | // If key data type do not match, it will return an error. |
| 2012 | // SYS-REQ-004 |
| 2013 | func GetFloat(data []byte, keys ...string) (val float64, err error) { |
| 2014 | v, t, _, e := Get(data, keys...) |
| 2015 | |
| 2016 | if e != nil { |
| 2017 | return 0, e |
| 2018 | } |
| 2019 | |
| 2020 | if t != Number { |
| 2021 | if t == Null { |
| 2022 | return 0, NullValueError |
| 2023 | } |
| 2024 | return 0, fmt.Errorf("Value is not a number: %s", string(v)) |
| 2025 | } |
| 2026 | |
| 2027 | return ParseFloat(v) |
| 2028 | } |
| 2029 | |
| 2030 | // GetInt returns the value retrieved by `Get`, cast to a int64 if possible. |
| 2031 | // If key data type do not match, it will return an error. |