Why 6.84 - 3.6 == 3.2399999999999998

前端 未结 7 762
星月不相逢
星月不相逢 2020-12-22 03:13

I just encountered this and can\'t figure out why exactly Ruby behaves this way.

Could someone explain why in Ruby:

6.84 - 3.6 == 3.2399999999999998
         


        
7条回答
  •  鱼传尺愫
    2020-12-22 03:43

    Because double/float use base-2 notation and decimal base-10 notation.

    Here's a useful link: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

提交回复
热议问题