用示例在Java中浮点 longValue()
Float Class中的Java.lang.Float.longValue()方法是Java中的内置方法,它在类型转换之后返回调用对象指定的值。
句法:
public long longValue()
参数:不带参数。
返回类型:它返回一个long值,即 FloatObject 的类型转换值。
下面是上述方法的实现。
方案一:
// Java Code to implement
// longValue() method of Float class
class GFG {
// Driver method
public static void main(String[] args)
{
// creating a Float object
Float d = new Float(1022);
// longValue() method of Float class
// typecast the value
long output = d.longValue();
// printing the output
System.out.println(output);
}
}
输出:
1022
方案二:
// Java Code to implement
// longValue() method of Float class
class GFG {
// Driver method
public static void main(String[] args)
{
// creating a Float object
Float d = new Float(-1023.23);
// longValue() method of Float class
// typecast the value
long output = d.longValue();
// printing the output
System.out.println(output);
}
}
输出:
-1023
参考: https: Java/lang/Float.html#longValue()