下载
npm install decimal.js
引入
Decimal.js import Decimal from 'decimal.js';
// 创建 Decimal 对象
var price = new Decimal('10.99');
var quantity = new Decimal('2');
// 进行精确计算
var total = price.times(quantity);
// 获取计算结果的字符串表示
var totalStr = total.toString();
console.log("总价:" + totalStr);
// 加法:使用 plus() 方法进行加法运算。
// 减法:使用 minus() 方法进行减法运算。
// 乘法:使用 times() 方法进行减法运算。
// 除法:使用 dividedBy() 方法进行除法运算。