MCPcopy Index your code
hub / github.com/cortexlabs/cortex / InterfaceToFloat64

Function InterfaceToFloat64

pkg/lib/cast/interface.go:341–364  ·  view source on GitHub ↗

InterfaceToFloat64 will convert any int or float type

(in interface{})

Source from the content-addressed store, hash-verified

339
340// InterfaceToFloat64 will convert any int or float type
341func InterfaceToFloat64(in interface{}) (float64, bool) {
342 var ok bool
343 if in, ok = JSONNumberToIntOrFloat(in); !ok {
344 return 0, false
345 }
346
347 switch casted := in.(type) {
348 case int8:
349 return float64(casted), true
350 case int16:
351 return float64(casted), true
352 case int32:
353 return float64(casted), true
354 case int:
355 return float64(casted), true
356 case int64:
357 return float64(casted), true
358 case float32:
359 return float64(casted), true
360 case float64:
361 return casted, true
362 }
363 return 0, false
364}
365
366func JSONNumberToInt(in interface{}) (interface{}, bool) {
367 number, ok := in.(json.Number)

Callers 5

Float64PtrFunction · 0.92
Float64Function · 0.92
Float64ListFunction · 0.92
TestInterfaceToFloat64Function · 0.85
InterfaceToFloat64SliceFunction · 0.85

Calls 1

JSONNumberToIntOrFloatFunction · 0.85

Tested by 1

TestInterfaceToFloat64Function · 0.68