Calculate large decimals (more than 15 digits) in Javascript

后端 未结 1 1505
陌清茗
陌清茗 2021-01-24 06:14

As we know, Javascript has some issues (or features) with calculating decimal numbers. For example:

相关标签:
1条回答
  • 2021-01-24 06:36

    I already answered this in the comment, but here's a demonstration. BigNumber will accept a number in string format for input.

    console.log(new BigNumber(0.1).plus("198.43092534959501"));
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/6.0.0/bignumber.min.js"></script>

    0 讨论(0)
提交回复
热议问题