Commit 2f0b88d5 authored by GuanHua's avatar GuanHua

fix: 商品单位是小数时,合计值问题

parent 6b1044b8
......@@ -861,11 +861,37 @@ const CommodityDetail = (props) => {
*/
const getAmount = (state = true) => {
const unitPrice = getUnitPrice()
const amount = unitPrice * (Number(buyCount) || 0)
const amount = accMul(unitPrice, buyCount)
return state ? priceFormat(amount) : amount
}
/**
** 乘法函数,用来得到精确的乘法结果
** 说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
** 调用:accMul(arg1,arg2)
** 返回值:arg1乘以 arg2的精确结果
**/
const accMul = (arg1: number, arg2: number) => {
if(!arg1 || !arg2){
return 0
}
let m = 0
const s1 = arg1.toString()
const s2 = arg2.toString()
try {
m += s1.split(".")[1].length;
} catch (e) {
console.log(e)
}
try {
m += s2.split(".")[1].length;
} catch (e) {
console.log(e)
}
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
}
/**
* 获取金额区间中数量最大的区间
*/
const getMaxCountRange = () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment