How to avoid scientific notation for large numbers in JavaScript?

后端 未结 22 2388
無奈伤痛
無奈伤痛 2020-11-22 00:31

JavaScript converts a large INT to scientific notation when the number becomes large. How can I prevent this from happening?

22条回答
  •  独厮守ぢ
    2020-11-22 00:52

    Your question:

    number :0x68656c6c6f206f72656f
    display:4.9299704811152646e+23
    

    You can use this: https://github.com/MikeMcl/bignumber.js

    A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic.

    like this:

    let ten =new BigNumber('0x68656c6c6f206f72656f',16);
    console.log(ten.toString(10));
    display:492997048111526447310191
    

提交回复
热议问题