-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnum.go
More file actions
executable file
·60 lines (51 loc) · 1.04 KB
/
Copy pathnum.go
File metadata and controls
executable file
·60 lines (51 loc) · 1.04 KB
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 Gconvert
import (
"log"
"strconv"
)
// int float转string
func Int2String(i interface{}) string {
switch i.(type) {
case int:
return strconv.FormatInt(int64(i.(int)), 10)
case int64:
return strconv.FormatInt(i.(int64), 10)
case float32:
return strconv.FormatFloat(float64(i.(float32)), 'f', -1, 32)
case float64:
return strconv.FormatFloat(i.(float64), 'f', -1, 64)
}
return ""
}
func Str2Int(s string) int {
ret, err := strconv.Atoi(s)
if err != nil {
log.Println("[!] Str2Int Error: ", err)
return 0
}
return ret
}
func Str2Int64(s string) int64 {
ret, err := strconv.ParseInt(s, 10, 64)
if err != nil {
log.Println("[!] Str2Int64 Error: ", err)
return 0
}
return ret
}
func Str2Float(s string) float32 {
ret, err := strconv.ParseFloat(s, 32)
if err != nil {
log.Println("[!] Str2Float Error: ", err)
return 0
}
return float32(ret)
}
func Str2Float64(s string) float64 {
ret, err := strconv.ParseFloat(s, 64)
if err != nil {
log.Println("[!] Str2Float64 Error: ", err)
return 0
}
return ret
}