- Java.math 包额外信息
- Java.math - 枚举
- Java.math - 讨论
Java.math.BigInteger.floatValue() 方法
说明
java.math.BigInteger.floatValue() 将此 BigInteger 转换为 float。此转换类似于 double 到 float 的缩小原始转换。
如果此 BigInteger 的幅度太大,无法表示为 float,它将适当地转换为 Float.NEGATIVE_INFINITY 或 Float.POSITIVE_INFINITY。即使返回值有限,此转换也可能会丢失有关 BigInteger 值精度的信息。
声明
以下是 java.math.BigInteger.floatValue() 方法的声明。
public float floatValue()
指定由
Number 类中的 floatValue。
参数
不适用
返回值
此方法返回此 BigInteger 转换为 float 后的值。
异常
不适用
示例
以下示例演示了 math.BigInteger.floatValue() 方法的用法。
package com.tutorialspoint;
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
// create 2 BigInteger objects
BigInteger bi1, bi2;
// create 2 Float objects
Float f1, f2;
// assign values to bi1, bi2
bi1 = new BigInteger("123");
bi2 = new BigInteger("-123");
// assign float values of bi1, bi2 to f1, f2
f1 = bi1.floatValue();
f2 = bi2.floatValue();
String str1 = "Float value of " + bi1 + " is " +f1;
String str2 = "Float value of " + bi2 + " is " +f2;
// print f1, f2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
让我们编译并运行上述程序,这将产生以下结果 −
Float value of 123 is 123.0 Float value of -123 is -123.0
java_math_biginteger.htm
广告