InterfaceToFloat32 will convert any int or float type
(in interface{})
| 313 | |
| 314 | // InterfaceToFloat32 will convert any int or float type |
| 315 | func InterfaceToFloat32(in interface{}) (float32, bool) { |
| 316 | var ok bool |
| 317 | if in, ok = JSONNumberToIntOrFloat(in); !ok { |
| 318 | return 0, false |
| 319 | } |
| 320 | |
| 321 | switch casted := in.(type) { |
| 322 | case int8: |
| 323 | return float32(casted), true |
| 324 | case int16: |
| 325 | return float32(casted), true |
| 326 | case int32: |
| 327 | return float32(casted), true |
| 328 | case int: |
| 329 | return float32(casted), true |
| 330 | case int64: |
| 331 | return float32(casted), true |
| 332 | case float32: |
| 333 | return casted, true |
| 334 | case float64: |
| 335 | return float32(casted), true |
| 336 | } |
| 337 | return 0, false |
| 338 | } |
| 339 | |
| 340 | // InterfaceToFloat64 will convert any int or float type |
| 341 | func InterfaceToFloat64(in interface{}) (float64, bool) { |
no test coverage detected