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
+24.5k Golang : GORM read from database example
+23.2k Golang : Print out struct values in string format
+31.1k Golang : Calculate percentage change of two values
+10.5k Swift : Convert (cast) String to Integer
+4.4k Linux/MacOSX : Search and delete files by extension
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+10.8k Golang : Natural string sorting example
+22.7k Golang : Strings to lowercase and uppercase example
+12.4k Golang : Extract part of string with regular expression
+21.8k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+19.9k Golang : Measure http.Get() execution time
+9.6k Golang : Copy map(hash table) example