How to convert a String containing Scientific Notation to correct Javascript number format

前端 未结 6 1117
深忆病人
深忆病人 2020-11-27 06:41

I have a String e.g: \"4.874915326E7\". What is the best way to convert it to a javascript number format? (int or float)? if I try parseInt(), the E

6条回答
  •  庸人自扰
    2020-11-27 07:01

    I had a value like this 3.53048874968162e-09 and using Number.toFixed(20) worked for me:

    value = new Number('3.53048874968162e-09')
    //[Number: 3.53048874968162e-9]
    value.toFixed(20)
    //'0.00000000353048874968'
    

提交回复
热议问题