This commit is contained in:
2025-04-02 10:35:17 +08:00
commit 89db955ec1
701 changed files with 91082 additions and 0 deletions

37
commons/utils/cal.js Normal file
View File

@@ -0,0 +1,37 @@
/**
* 数字, 计算相关函数
*
* @author terrfly
* @site https://www.jeepay.vip
* @date 2022/11/22 10:38
*/
/**
* 保留小数n位不进行四舍五入
* num你传递过来的数字,
* decimal你保留的几位,默认保留小数后两位
*/
const formatDecimal = function(num, decimal = 2) {
num = num.toString()
const index = num.indexOf('.')
if (index !== -1) {
num = num.substring(0, decimal + index + 1)
} else {
num = num.substring(0)
}
//截取后保留两位小数
return parseFloat(num).toFixed(decimal)
}
const model = {
// 分转元
// amount - 金额 parseFloat - 是否转换为数字格式, 默认String
cert2Dollar(amount, needParseFloat = false) {
if (needParseFloat) { // parseFlot
return formatDecimal(amount / 100)
}
return formatDecimal(amount / 100)
}
}
export default model