big.js常用API

plus

0.1 + 0.2                                     // 0.30000000000000004
const x = new Big (0.1);
const y = x.plus (0.2);                      // 0.3
Big (0.7).plus (x).plus (y).toFixed (2);     // 1.1
复制代码

minus

0.3 - 0.1                                     // 0.19999999999999998   
const x = new Big (0.3);
const y = x.minus (0.1)                      // 0.2
(Big (0.7).minus (x).minus (y).toFixed (2)   // 0.2
复制代码

times

0.6 * 3                    // 1.7999999999999998
x = new Big(0.6)
y = x.times(3)             // '1.8'
Big('7e+500').times(y)     // '1.26e+501'
复制代码

div

x = new Big(355)
y = new Big(113)
x.div(y)                   // '3.14159292035398230088'
Big.DP = 2
x.div(y)                   // '3.14'
x.div(5)                   // '71'
复制代码

eq

0 === 1e-324               // true
x = new Big(0)
x.eq('1e-324')             // false
Big(-0).eq(x)              // true  ( -0 === 0 )
复制代码

转载于:https://juejin.im/post/5cfe16eff265da1b6c5f6b23

猜你喜欢

转载自blog.csdn.net/weixin_33862993/article/details/91466217