Java Widening Conversion

时间:2018-03-08 22:11:11

标签: java precision

int big = 1234567890; float approx = big; System.out.println(big - (int)approx);

The system prints out -46. I thought that float only allows for 7 significant figures meaning the operation would be 1234567890-1234567=1,233,333,323. How is it possible for it to print -46?

1 个答案:

答案 0 :(得分:2)

我认为对短语"重要数字"的解释存在问题?

你是否有

1234567890 US-dollars

1234567936 US-dollars

不是差异显着

但如果你改为

   1234567 US-dollars

这将是非常显着差异。

1234567890
^       ^
|        \
|         less significant
|
very significant

因此,近似

1234567890

到7位十进制有效数字是(大约)

之间的东西
1234567390

和(大约)

1234568390

在这种情况下,结果大致是

1234567936
相关问题