js 浮点数工具

    github官网:https://github.com/MikeMcl/bignumber.js

    原因:
    image.pngimage.png

    引用:

    1. <script src="https://cdn.bootcss.com/bignumber.js/9.0.0/bignumber.min.js"></script>
    1. npm install bignumber.js
    2. import BigNumber from "./bignumber.mjs"

    示例:

    1. let a = new BigNumber(123.123);
    2. let b = BigNumber(12.23323);
    3. // let c = a.plus(b); // 135.35623
    4. // let c = a.minus(b); // 110.88977
    5. // let c = a.multipliedBy(b); // 1506.19197729
    6. let c = a.dividedBy(b); // 10.064635423350987
    7. console.log(c.toFixed(3)); // 保留3位小数
    8. console.log(c.toNumber()); // 默认输出

    方法一览表:

    image.png