math.go 862 字节
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
}