-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
33 lines (31 loc) · 728 Bytes
/
utils.go
File metadata and controls
33 lines (31 loc) · 728 Bytes
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
package formula_engine
import (
"fmt"
"math/big"
)
// GetInterfaceStringValue 获取Interface的String值
func GetInterfaceStringValue(v interface{}) string {
if v == nil {
return ""
}
switch v.(type) {
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
return fmt.Sprintf("%d", v)
case float32, float64:
return fmt.Sprintf("%0.8f", v)
case string:
return fmt.Sprintf("%s", v)
case []uint8:
vInner, _ := v.([]uint8)
byteList := make([]byte, len(vInner))
for index, uintV := range vInner {
byteList[index] = uintV
}
return string(byteList)
case *big.Rat:
floatV, _ := v.(*big.Rat).Float64()
return fmt.Sprintf("%f", floatV)
default:
return fmt.Sprintf("%v", v)
}
}