Java float unexpectedly rounded

前端 未结 3 369
暖寄归人
暖寄归人 2021-01-17 03:12

I\'m using a float constant and setting a objects private float variable to the float constant below, but when the object outputs the value it was set to, it\'s rounding up

3条回答
  •  不思量自难忘°
    2021-01-17 04:04

    Floats can't represent every number, so numbers are rounded. Doubles are the same, but with a higher precision. If you use Double your output will be 956.35625 (in this special case).

提交回复
热议问题