1 Star 0 Fork 0

小于的个人工具集/xnum

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
discount.go 484 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoyutab 提交于 2023-12-15 15:01 +08:00 . 1
package xnum
import "math"
// 计算金额的折扣费率
// 此处使用math.Floor进行向下取整的方式,即低于0.01的部分直接舍弃
//
// price 待计算的金额
// discount 费率,0~100
func Discount(price float64, discount uint8) float64 {
if discount > 100 {
discount = 100
}
// 取整方式
// 向上取整 math.Ceil(x)
// 向下取整 math.Floor(x)
// 四舍五入取整 math.Floor(x + 0.5)
return math.Floor(price*100*float64(discount)/100) / 100
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xgotool/xnum.git
git@gitee.com:xgotool/xnum.git
xgotool
xnum
xnum
5661bb6dee89

搜索帮助