-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.go
More file actions
60 lines (48 loc) · 836 Bytes
/
Copy pathtools.go
File metadata and controls
60 lines (48 loc) · 836 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
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 fixnum
import "go.uber.org/zap"
func GetDigits(s string) int64 {
dot := -1
for i, c := range s {
if c == '.' {
dot = i
break
}
}
if dot == -1 {
return 0
}
frac := s[dot+1:]
// 去掉尾部 0
end := len(frac)
for end > 0 && frac[end-1] == '0' {
end--
}
return int64(end)
}
func GetScaleFromDigits(digits int64) int64 {
scale := int64(1)
for range digits {
scale *= 10
}
return scale
}
func Min(a, b Decimal) Decimal {
if a.Lte(b) {
return a
}
return b
}
func Max(a, b Decimal) Decimal {
if a.Gte(b) {
return a
}
return b
}
// 向下取整到步长的整数倍
func FloorToStep(value Decimal, tick Decimal) Decimal {
if tick.IsZero() {
zap.S().Errorf("❌ FloorToStep tick is zero, value: %+v, tick: %+v", value, tick)
return value
}
return value.Sub(value.Mod(tick))
}