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

Function GetFloat

parser.go:1881–1896  ·  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

1879// If key data type do not match, it will return an error.
1880// SYS-REQ-004
1881func GetFloat(data []byte, keys ...string) (val float64, err error) {
1882 v, t, _, e := Get(data, keys...)
1883
1884 if e != nil {
1885 return 0, e
1886 }
1887
1888 if t != Number {
1889 if t == Null {
1890 return 0, NullValueError
1891 }
1892 return 0, fmt.Errorf("Value is not a number: %s", string(v))
1893 }
1894
1895 return ParseFloat(v)
1896}
1897
1898// GetInt returns the value retrieved by `Get`, cast to a int64 if possible.
1899// If key data type do not match, it will return an error.

Calls 2

GetFunction · 0.85
ParseFloatFunction · 0.85