Java如何将double值转换为int值?
要将double值转换为int值,我们可以使用类型转换或Double.intValue()方法调用。下面的代码段向您展示了如何执行此操作。
package org.nhooo.example.lang;
public class DoubleToInt {
public static void main(String[] args) {
Double numberA = 49.99;
System.out.println("numberA = " + numberA);
// 通过调用将Double值转换为int值
// Double.intValue()方法。
int numberB = numberA.intValue();
System.out.println("numberB = " + numberB);
// 通过强制转换将Double值转换为int值
// Double实例的原始double值
int numberC = (int) numberA.doubleValue();
System.out.println("numberC = " + numberC);
double numberD = 99.99;
System.out.println("numberD = " + numberD);
// 使用将双精度值转换为int值
// 类型转换
int numberE = (int) numberD;
System.out.println("numberE = " + numberE);
}
}
热门推荐
10 完成预算祝福语简短精辟
11 过生日祝福语简短爸爸
12 关于长辈祝福语大全简短
13 朋友聚会结束祝福语简短
14 文艺乔迁祝福语简短精辟
15 提前生日祝福语 简短
16 校庆祝福语简短独特
17 生日贺卡祝福语英文简短
18 天仙配简短祝福语