java.math.BigInteger floatValue()
Description
For reference the byte range is from 1.4E-45 to 3.4028235E38 and these information is readily available through the Float constants Float.MIN_VALUE and Float.MAX_VALUE.
Notes:
- This method is specified by floatValue in class Number.
Method Syntax
public float floatValue()
Method Argument
Data Type | Parameter | Description |
---|---|---|
N/A | N/A | N/A |
Method Returns
The doubleValue() method returns this BigInteger converted to a float.
Compatibility
Requires Java 1.1 and up
Java BigInteger floatValue() Example
Below is a java code demonstrates the use of floatValue() method of BigInteger class. The example presented might be simple however it shows the behavior of the floatValue() method.
package com.javatutorialhq.java.examples; import java.math.BigInteger; import java.util.Scanner; /* * A java example source code to demonstrate * the use of floatValue() method of BigInteger class */ public class BigIntegerFloatValueExample { public static void main(String[] args) { // Declare and initialize our BigInteger values BigInteger val1 = new BigInteger("12"); BigInteger val2 = new BigInteger("4565451257489787"); // get the float equivalent of each BigInteger double floatVal1 = val1.floatValue(); double floatVal2 = val2.floatValue(); // print the operation System.out.println("val1 in float is "+floatVal1); System.out.println("val2 in float is "+floatVal2); } }
This example is a lot simpler than it looks. We only initialize two BigInteger and then convert these into float. The result of the floatValue is printed out to simulate the conversion.