different values for float and double

前端 未结 5 545
独厮守ぢ
独厮守ぢ 2021-01-08 01:16

I don\'t understand why are float values different from double values. From the example bellow it appears that float provides different result than double for the same opera

5条回答
  •  天命终不由人
    2021-01-08 01:35

    A float is a 32 bit IEEE 754 floating point.

    A double is a 64 bit IEEE 754 floating point.

    so it is just a matter of precision because neither of the fraction portions .8 and .65 have a terminating binary representation, so there is some rounding error. the double has more precision so it has slightly less rounding error.

    http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

提交回复
热议问题