本文介绍了为什么Math.floor会返回一个双精度数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
官方javadoc 说 Math.floor返回一个等于数学整数的double,但是为什么不能返回一个int?
Official javadoc says that Math.floor returns a double that is "equal to a mathematical integer", but then why shouldn't it return an int?
推荐答案根据相同的javadoc:
According to the same javadoc:
如果参数为NaN或无穷大或正零或负零,则结果与参数相同。不能用int做到这一点。
If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument. Can't do that with an int.
最大的double值也大于最大的int,所以它必须是一个很长的。
The largest double value is also larger than the largest int, so it would have to be a long.
更多推荐
为什么Math.floor会返回一个双精度数?
发布评论