const oneVolume = (data, i) => { // 货物-单箱体积 // 单箱体积=长*宽*高 data[i].singleBoxVolume = Number( (data[i].length * data[i].wide * data[i].high) / 1000000 ); }; const getTotalVolume = (data, i) => { // 货物-总体积 // 总体积=单箱体积*箱数 data[i].totalVolume = Number(data[i].singleBoxVolume * data[i].ctns); }; const getTotalWeight = (data, i) => { // 货物-总重量 // 总重量=单箱重量*箱数 data[i].totalWeight = Number(data[i].singleBoxWeight * data[i].ctns); }; const getTotalRatio = (data, i) => { // 货物-泡重比 if ( data[i].totalVolume != 0 && !isNaN(Number(data[i].totalWeight)) && !isNaN(Number(data[i].totalVolume)) ) { data[i].bubbleWeightRatio = 1 + " : " + (data[i].totalWeight / data[i].totalVolume); } else { data[i].bubbleWeightRatio = 1 + " : " + 0; } };以上方法都改成使用big.js
时间: 2024-04-12 17:34:16 浏览: 102
vue省市区/县数据js文件(citydata.js)
const Big = require('big.js');
const oneVolume = (data, i) => {
data[i].singleBoxVolume = new Big(data[i].length)
.times(data[i].wide)
.times(data[i].high)
.div(1000000)
.toNumber();
};
const getTotalVolume = (data, i) => {
data[i].totalVolume = new Big(data[i].singleBoxVolume)
.times(data[i].ctns)
.toNumber();
};
const getTotalWeight = (data, i) => {
data[i].totalWeight = new Big(data[i].singleBoxWeight)
.times(data[i].ctns)
.toNumber();
};
const getTotalRatio = (data, i) => {
if (
data[i].totalVolume !== 0 &&
!isNaN(Number(data[i].totalWeight)) &&
!isNaN(Number(data[i].totalVolume))
) {
data[i].bubbleWeightRatio = `1 : ${new Big(data[i].totalWeight).div(
data[i].totalVolume
)}`;
} else {
data[i].bubbleWeightRatio = `1 : 0`;
}
};
以上方法都已使用 Big.js 进行了修改,以确保精确计算。
阅读全文