How to avoid scientific notation for large numbers in JavaScript?

后端 未结 22 2047
無奈伤痛
無奈伤痛 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 01:08

    If you are just doing it for display, you can build an array from the digits before they're rounded.

    var num = Math.pow(2, 100);
    var reconstruct = [];
    while(num > 0) {
        reconstruct.unshift(num % 10);
        num = Math.floor(num / 10);
    }
    console.log(reconstruct.join(''));
    

提交回复
热议问题