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
+8.6k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+16.5k Golang : Check if a string contains multiple sub-strings in []string?
+8.3k Swift : Convert (cast) Character to Integer?
+5.9k Golang : Denco multiplexer example
+13.9k Golang : How to check if a file is hidden?
+6.3k Apt-get to install and uninstall Golang
+6.9k Nginx : Password protect a directory/folder
+8.6k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+47.8k Golang : Convert int to byte array([]byte)
+16.4k Golang : Test floating point numbers not-a-number and infinite example
+7.8k Golang : Reverse a string with unicode
+4.7k Golang : How to pass data between controllers with JSON Web Token