Float64 coerces into a float64
()
| 27 | |
| 28 | // Float64 coerces into a float64 |
| 29 | func (j *Json) Float64() (float64, error) { |
| 30 | switch j.data.(type) { |
| 31 | case json.Number: |
| 32 | return j.data.(json.Number).Float64() |
| 33 | case float32, float64: |
| 34 | return reflect.ValueOf(j.data).Float(), nil |
| 35 | case int, int8, int16, int32, int64: |
| 36 | return float64(reflect.ValueOf(j.data).Int()), nil |
| 37 | case uint, uint8, uint16, uint32, uint64: |
| 38 | return float64(reflect.ValueOf(j.data).Uint()), nil |
| 39 | } |
| 40 | return 0, errors.New("invalid value type") |
| 41 | } |
| 42 | |
| 43 | // Int coerces into an int |
| 44 | func (j *Json) Int() (int, error) { |