如何将 Double 对象转换为 int?以下代码有效,但似乎有点不合常规(两次强制转换):
Double d = new Double(4.0);
int i = (int)(double)d;
当我尝试 int i = (int)d
时,我从 Eclipse 中得到一个错误(Cannot cast from Double to int
),这是有道理的。不过,是否有更简单的方法将 Double 对象转换为 int?
最佳答案
Double.intValue()
是执行该转换的提供方法。
关于java - 将 Double 对象转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26247049/