forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.go
60 lines (53 loc) · 866 Bytes
/
Utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package goex
import (
"strconv"
)
func ToFloat64(v interface{}) float64 {
if v == nil {
return 0.0
}
switch v.(type) {
case float64:
return v.(float64)
case string:
vStr := v.(string)
vF, _ := strconv.ParseFloat(vStr, 64)
return vF
default:
panic("to float64 error.")
}
}
func ToInt(v interface{}) int {
if v == nil {
return 0
}
switch v.(type) {
case string:
vStr := v.(string)
vInt, _ := strconv.Atoi(vStr)
return vInt
case int:
return v.(int)
case float64:
vF := v.(float64)
return int(vF)
default:
panic("to int error.")
}
}
func ToUint64(v interface{}) uint64 {
if v == nil {
return 0
}
switch v.(type) {
case int:
return uint64(v.(int))
case float64:
return uint64((v.(float64)))
case string:
uV, _ := strconv.ParseUint(v.(string), 10, 64)
return uV
default:
panic("to uint64 error.")
}
}