math.go
862 字节
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
package utils
import (
"github.com/shopspring/decimal"
"math"
"math/rand"
"time"
)
func decimal1(value float64) float64 {
return math.Trunc(value*1e1+0.5) * 1e-1
}
func Round(value float64, places int32) float64 {
quantity := decimal.NewFromFloat(value)
d := quantity.Round(places)
rsp, _ := d.Float64()
return rsp
}
func Decimal(value float64) float64 {
return Round(value, 2)
}
func DecimalToNumber(value float64) float64 {
return Round(value, 2)
}
func GenerateRangeNum(min, max int) int {
rand.Seed(time.Now().Unix())
randNum := rand.Intn(max-min) + min
return randNum
}
/**
* @Author SteveChan
* @Description // 判断数组是否包含
* @Date 14:30 2021/1/6
* @Param
* @return
**/
func IsContain(items []string, item string) bool {
for _, eachItem := range items {
if eachItem == item {
return true
}
}
return false
}