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