Big.js 常用操作

加法

0.1 + 0.2                  // 0.30000000000000004

x = new Big(0.1)

y = x.plus(0.2)            // '0.3'

Big(0.7).plus(x).plus(y)   // '1.1'

 

 

减法

0.3 - 0.1                          // 0.19999999999999998

x = new Big(0.3)

x.minus(0.1)                       // "0.2"

x                                  // “0.3"

 

乘法

0.6 * 3                    // 1.7999999999999998

x = new Big(0.6)

y = x.times(3)             // '1.8'

 

除法

x = new Big(2);

y = new Big(3);

z = x.div(y)                       // "0.6666666667"

 

绝对值

x = new Big(-0.8)

x.abs()                     // ‘0.8'

 

模运算

1 % 0.9                    // 0.09999999999999998

x = new Big(1)

x.mod(0.9)                 // '0.1'

你可能感兴趣的:(Big.js)