MCPcopy Create free account
hub / github.com/buger/jsonparser / GetFloat

Function GetFloat

parser.go:2013–2028  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2011// If key data type do not match, it will return an error.
2012// SYS-REQ-004
2013func 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.

Calls 2

GetFunction · 0.85
ParseFloatFunction · 0.85