Apparent F#/BCL floating point bug

前端 未结 3 1759
清酒与你
清酒与你 2021-01-21 11:17

The following is in FSI:

> System.Math.Round(0.2916, 2);;
val it : float = 0.29
> it * 100.;;
val it : float = 29.0
> int it;;
val it : int = 28
         


        
3条回答
  •  情书的邮戳
    2021-01-21 11:31

    This is just how floating point numbers work. The number that appears as 29 in the output is actually slightly smaller than 29 (because floating point numbers are not precise):

    > (System.Math.Round(0.2916, 2) * 100.0) - 29.0;;
    val it : float = -3.552713679e-15
    

提交回复
热议问题