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
+20.6k Nginx + FastCGI + Go Setup.
+6.5k Golang : Convert an executable file into []byte example
+11.6k Golang : Display a text file line by line with line number example
+8.3k Golang : Check if integer is power of four example
+10.5k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)
+15.3k Golang : Delete certain files in a directory
+12.6k Golang : Exit, terminating or aborting a program
+14k Golang : Compress and decompress file with compress/flate example
+30k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+24k Golang : Call function from another package
+6.8k Android Studio : Hello World example
+12.7k Golang : Sort and reverse sort a slice of bytes