代码拉取完成,页面将自动刷新
package utils
import (
"github.com/shopspring/decimal"
"strconv"
)
//分转元
func Fen2YuanString(price int64) string {
d := decimal.New(1, 2) //分除以100得到元
result := decimal.NewFromInt(price).DivRound(d, 2).String()
return result
}
//分转元
func Fen2YuanInt64(price int64) int64 {
d := decimal.New(1, 2) //分除以100得到元
result := decimal.NewFromInt(price).DivRound(d, 2).IntPart()
return result
}
//元转分,乘以100后,保留整数部分
func StringYuan2FenInt64(price string) int64 {
float64Price, _ := strconv.ParseFloat(price, 64)
int64Price := Float64Yuan2FenInt64(float64Price)
return int64Price
}
//元转分,乘以100后,保留整数部分
func Float64Yuan2FenInt64(price float64) int64 {
d := decimal.New(1, 2) //分转元乘以100
df := decimal.NewFromFloat(price).Mul(d).IntPart()
//d1 := decimal.New(1, 0) //乘完之后,保留2为小数,需要这么一个中间参数
//如下是满足,当乘以100后,仍然有小数位,取四舍五入法后,再取整数部分
//dff := decimal.NewFromFloat(price).Mul(d).DivRound(d1, 0).IntPart()
return df
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。