[removed] Round to a number of decimal places, but strip extra zeros

前端 未结 8 2191
鱼传尺愫
鱼传尺愫 2020-12-02 12:00

Here\'s the scenario: I\'m getting .9999999999999999 when I should be getting 1.0.
I can afford to lose a decimal place of precision, so I\'m u

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 12:14

    >>> parseFloat(0.9999999.toFixed(4));
    1
    >>> parseFloat(0.0009999999.toFixed(4));
    0.001
    >>> parseFloat(0.0000009999999.toFixed(4));
    0
    

提交回复
热议问题