How to avoid scientific notation for large numbers in JavaScript?

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

    For small number, and you know how many decimals you want, you can use toFixed and then use a regexp to remove the trailing zeros.

    Number(1e-7).toFixed(8).replace(/\.?0+$/,"") //0.000
    

提交回复
热议问题