The java.math.BigDecimal.floatValue() converts this BigDecimal to a float. If this BigDecimal has too great magnitude to represent as a float, it will be converted to Float.NEGATIVE_INFINITY or Float.POSITIVE_INFINITY as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigDecimal value.
public float floatValue()
Parameters: This function accepts no parameter.
Returns: The method returns a float value which represents float value for this BigDecimal.
Input: BigDecimal1 = 1234 Output: 1234.0 Input: BigDecimal1 = 21545135451354545 Output: 2.15451365E16 Explanation: BigInteger1.floatValue() = 2.15451365E16. This BigDecimal is too big for a magnitude to represent as a float then it will be converted to Float.NEGATIVE_INFINITY or Float.POSITIVE_INFINITY as appropriate.
Below programs illustrate floatValue() method of BigDecimal class:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.