-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_float.go
57 lines (49 loc) · 1.4 KB
/
convert_float.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
package cdt
// ToFloat64E function to convert other type data to float64, with error
func (i *convert) ToFloat64E() (float64, error) {
return toFloat64(i.GetOriginValRef())
}
// ToFloat64Ptr function to convert other type data to float64, with pointer
func (i *convert) ToFloat64Ptr() *float64 {
v, _ := i.ToFloat64E()
return &v
}
// ToFloat64PtrE function to convert other type data to float64, with pointer and error
func (i *convert) ToFloat64PtrE() (*float64, error) {
v, err := i.ToFloat64E()
if err != nil {
return nil, err
}
return &v, nil
}
// ToFloat64 function to convert other type data to float64
func (i *convert) ToFloat64() float64 {
v, _ := i.ToFloat64E()
return v
}
// ToFloat32E function to convert other type data to float32
func (i *convert) ToFloat32E() (float32, error) {
number, err := i.ToFloat64E()
if err != nil {
return float32(0), err
}
return float32(number), nil
}
// ToFloat32Ptr function to convert other type data to float32, with pointer
func (i *convert) ToFloat32Ptr() *float32 {
v, _ := i.ToFloat32E()
return &v
}
// ToFloat32PtrE function to convert other type data to float32, with pointer and error
func (i *convert) ToFloat32PtrE() (*float32, error) {
v, err := i.ToFloat32E()
if err != nil {
return nil, err
}
return &v, nil
}
// ToFloat32 function to convert other type data to float32
func (i *convert) ToFloat32() float32 {
v, _ := i.ToFloat32E()
return v
}