toFixed(2) rounds “x.525” inconsistently?

前端 未结 4 463
半阙折子戏
半阙折子戏 2020-12-06 13:20

I\'m experiencing rounding errors when using toFixed:

I used toFixed(2) on my numeric value calculations, but the rounding results are not as expected

4条回答
  •  借酒劲吻你
    2020-12-06 14:04

    Floating point inaccuracy means that most numbers ending .525 are actually .52500..1, and others are .5249999.....

    Which way the value rounds depends on whether the closest actual representation in IEEE-754 floating point is above or below the desired value.

提交回复
热议问题