Java floatValue()方法
floatValue()方法
Java中的floatValue()方法,可将继承自Number类对象,比如Byte、Integer、Short、Long、Double、Float等类型对象,转换为float形式的数值。其语法如下:
NumberObj.floatValue()
floatValue()方法实例代码
下方实例中,将上述几种继承自Number类的Byte、Integer、Short、Long、Double等包装类的对象转换为float值:
public class test {
public static void main(String[] args) {
Integer a = 3;
float x = a.floatValue();
Double b = 6.2;
float y = b.floatValue();
Long c = 9L;
float z = c.floatValue();
Short d = 2;
float n = d.floatValue();
System.out.println("x="+x+",y="+y+",z="+z+",n="+n);
}
}
免责声明:内容仅供参考,不保证正确性!