convert.go
936 字节
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
package utils
import "strconv"
type NumberString string
func (s NumberString) String() string {
return string(s)
}
func (s NumberString) Int() (int, error) {
v, err := strconv.Atoi(s.String())
return v, err
}
func (s NumberString) MustInt() int {
v, _ := s.Int()
return v
}
func (s NumberString) UInt32() (uint32, error) {
v, err := strconv.Atoi(s.String())
return uint32(v), err
}
func (s NumberString) MustUInt32() uint32 {
v, _ := s.UInt32()
return v
}
func (s NumberString) Int64() (int64, error) {
v, err := strconv.ParseInt(s.String(), 10, 64)
return v, err
}
func (s NumberString) MustInt64() int64 {
v, _ := s.Int64()
return v
}
func (s NumberString) Float64() (float64, error) {
return strconv.ParseFloat(s.String(), 64)
}
func (s NumberString) MustFloat64() float64 {
v, _ := strconv.ParseFloat(s.String(), 64)
return v
}
func NewNumberString(str string) NumberString {
return NumberString(str)
}