yarn add big.js
<template>
<div>4563</div>
</template>
<script>
import Big from "big.js";
export default {
data() {
return {
testValue: [
{
value: 0.1,
},
{
value: 200.111,
},
],
};
},
created() {
//加法 plus
let result = this.testValue.reduce((prev, next) => {
return parseFloat(new Big(prev.value).plus(next.value));
});
//乘法 times
let newResult = this.testValue.reduce((prev, next) => {
return parseFloat(new Big(prev.value).times(next.value));
});
//减法 minus
let descNumber = this.testValue.reduce((prev, next) => {
return parseFloat(new Big(prev.value).minus(next.value));
});
//除法 div
let testResult = this.testValue.reduce((prev, next) => {
return parseFloat(new Big(prev.value).div(next.value));
});
console.log(result, newResult, descNumber, testResult);
},
};
</script>
解决js精度丢失问(big.js)
最新推荐文章于 2024-07-11 14:04:18 发布