Golang encoding/json.Number.Int64 function example
package encoding/json
Int64 returns the number as an int64.
Golang encoding/json.Number.Int64 function usage example
func (j *Json) Float64() (float64, error) {
switch j.data.(type) {
case json.Number:
return j.data.(json.Number).Int64() // <---- 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
+14.3k Golang : How to shuffle elements in array or slice?
+22.2k Golang : Securing password with salt
+21.3k Golang : Create and resolve(read) symbolic links
+7.9k Golang Hello World Example
+9.1k Golang : Simple histogram example
+43.2k Golang : Convert []byte to image
+16.8k Golang : Get own process identifier
+8.6k Golang : Convert(cast) []byte to io.Reader type
+22.9k Golang : Gorilla mux routing example
+21.4k Curl usage examples with Golang
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date
+11.8k Golang : Verify Linux user password again before executing a program example