day02-数据类型转换_强制转换-小数的转换

This commit is contained in:
2026-07-15 16:12:44 +08:00
parent 1e2a39dd8b
commit 7437650f86

View File

@@ -0,0 +1,19 @@
package com.inmind.datatype;
/**
小数强转为整数,如何操作的??强制类型转换
小数转为整数的结果:直接将小数的小数位去掉(精度丢失)
*/
public class Demo04 {
public static void main(String[] args) {
//定义一个单精度浮点数变量
float f = 3.14F;
//能不能转为整数??
int i = (int) f;
System.out.println(i);//3
//定义一个单精度浮点数变量
double d = 3.1425926;
//能不能转为字节??
byte b = (byte) d;
System.out.println(b);
}
}