- Java.math package classes
- Java.math - Home
- Java.math - BigDecimal
- Java.math - BigInteger
- Java.math - MathContext
- Java.math package extras
- Java.math - Enumerations
- Java.math - Discussion
Java.math.BigInteger.floatValue() Method
Description
The java.math.BigInteger.floatValue() converts this BigInteger to a float. This conversion is similar to the narrowing primitive conversion from double to float.
If this BigInteger has too great a magnitude to represent as a float, it will be converted to Float.NEGATIVE_INFINITY or Float.POSITIVE_INFINITY as appropriate. Even when the return value is finite, this conversion can lose information about the precision of the BigInteger value.
Declaration
Following is the declaration for java.math.BigInteger.floatValue() method.
public float floatValue()
Specified by
floatValue in class Number.
Parameters
NA
Return Value
This method returns this BigInteger converted to a float.
Exception
NA
Example
The following example shows the usage of math.BigInteger.floatValue() method.
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 ); } }
Let us compile and run the above program, this will produce the following result −
Float value of 123 is 123.0 Float value of -123 is -123.0
To Continue Learning Please Login
Login with Google