Golang encoding/json.Number.Float64 function example
package encoding/json
Float64 returns the number as a float64.
Golang encoding/json.Number.Float64 function usage example
func (j *Json) Float64() (float64, error) {
switch j.data.(type) {
case json.Number:
return j.data.(json.Number).Float64() // <---- here
case float32, float64:
return reflect.ValueOf(j.data).Float(), nil
case int, int8, int16, int32, int64:
return float64(reflect.ValueOf(j.data).Int()), nil
case uint, uint8, uint16, uint32, uint64:
return float64(reflect.ValueOf(j.data).Uint()), nil
}
return 0, errors.New("invalid value type")
}
Reference :
Advertisement
Something interesting
Tutorials
+9.6k Golang : Copy map(hash table) example
+21.8k Golang : How to reverse slice or array elements order
+14.5k How to automatically restart your crashed Golang server
+17.2k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+8.2k Golang : Reverse text lines or flip line order example
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+13.8k Golang : unknown escape sequence error
+27.9k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+6.3k Golang : Selection sort example
+19.3k Golang : Get RGBA values of each image pixel
+16.9k Golang : How to generate QR codes?
+4.9k Nginx and PageSpeed build from source CentOS example