BigDecimal floatValue() Method in Java with Examples Last Updated : 27 May, 2019 Comments Improve Suggest changes Like Article Like Report 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. Syntax: public float floatValue() Parameters: This function accepts no parameter. Returns: The method returns a float value which represents float value for this BigDecimal. Examples: 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: Example 1: Java // Java program to demonstrate // floatValue() method of BigDecimal import java.math.BigDecimal; public class GFG { public static void main(String[] args) { // For user input // Use Scanner or BufferedReader // Object of String created // Holds the value String input1 = "545456468445645468464645"; // Convert the string input to BigDecimal BigDecimal a = new BigDecimal(input1); // Using floatValue() method float f = a.floatValue(); // Display the result System.out.println(f); } } Output: 5.4545646E23 Example 2: Java // Java program to demonstrate // floatValue() method of BigDecimal import java.math.BigDecimal; public class GFG { public static void main(String[] args) { // For user input // Use Scanner or BufferedReader // Object of String created // Holds the value String input1 = "984522"; // Convert the string input to BigDecimal BigDecimal a = new BigDecimal(input1); // Using floatValue() method float f = a.floatValue(); // Display the result System.out.println(f); } } Output: 984522.0 References: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#floatValue() Comment More infoAdvertise with us Next Article BigDecimal floatValue() Method in Java with Examples R Rajnis09 Follow Improve Article Tags : Java Java-Functions Java-BigDecimal Java-math-package Practice Tags : Java Similar Reads Byte floatValue() method in Java with examples The floatValue() method of Byte class is a built in method in Java which is used to return the value of this Byte object as float. Syntax ByteObject.floatValue() Return Value: It return the value of ByteObject as float. Below is the implementation of floatValue() method in Java: Example 1: Java // J 2 min read AtomicLong floatValue() method in Java with examples The Java.util.concurrent.atomic.AtomicLong.floatValue() is an inbuilt method in java which returns the current value of the AtomicLong as a Float data-type after performing primitive conversion. Syntax: public float floatValue() Parameters: The function does not accepts any parameter. Return value: 1 min read DoubleAdder floatValue() method in Java with Examples The java.DoubleAdder.floatValue() is an inbuilt method in java that returns the sum() as an float after a narrowing primitive conversion. When the object of the class is created its initial value is zero. Syntax: public float floatValue() Parameters: This method does not accepts any parameter. Retur 1 min read DoubleAccumulator floatValue() method in Java with Examples The Java.DoubleAccumulator.floatValue() is an inbuilt method in java that returns the current value as an float after a narrowing primitive conversion. It means the initial datatype is double which is explicitly converted into type float. Syntax: public float floatValue() Parameters: The function do 2 min read BigDecimal add() Method in Java with Examples The java.math.BigDecimal.add(BigDecimal val) is used to calculate the Arithmetic sum of two BigDecimals. This method is used to find arithmetic addition of large numbers of range much greater than the range of largest data type double of Java without compromising with the precision of the result. Th 3 min read Like