int_util.go
1.12 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package webutility
import (
"fmt"
)
// ClampInt64 ...
func ClampInt64(v, min, max int64) int64 {
if v < min {
return min
} else if v > max {
return max
}
return v
}
// InRangeInt64 ...
func InRangeInt64(v, min, max int64) bool {
return (v >= min && v <= max)
}
// Int64ToString ...
func Int64ToString(i int64) string {
return fmt.Sprintf("%d", i)
}
// Int64PtrToString ...
func Int64PtrToString(i *int64) string {
if i == nil {
return ""
}
return fmt.Sprintf("%d", *i)
}
// BoolToInt64 ...
func BoolToInt64(b bool) int64 {
if b {
return 1
}
return 0
}
// Int64ToBool ...
func Int64ToBool(i int64) bool {
return i != 0
}
func MaxInt(vars ...int) (max int) {
max = vars[0]
for _, v := range vars {
if v > max {
max = v
}
}
return max
}
func MinInt64(vars ...int64) (min int64) {
min = vars[0]
for _, v := range vars {
if v < min {
min = v
}
}
return min
}
func FormatInt64Number(i int64) string {
res := ""
for i >= 1000 {
rem := i % 1000
i = i / 1000
//res = res + fmt.Sprintf(".%03d", rem)
res = fmt.Sprintf(".%03d", rem) + res
}
res = fmt.Sprintf("%d", i) + res
return res
}