How to avoid scientific notation for large numbers in JavaScript?

后端 未结 22 2021
無奈伤痛
無奈伤痛 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:49

    Use .toPrecision, .toFixed, etc. You can count the number of digits in your number by converting it to a string with .toString then looking at its .length.

提交回复
热议问题