Skip to content
Related Articles

Related Articles

Improve Article

Number.floatValue() method in java with examples

  • Last Updated : 20 Jun, 2018

The java.lang.Number.floatValue() is an inbuilt method in java that returns the value of the specified number casted to float data type. This may involve rounding or truncation.

Syntax:

public abstract float floatValue()

Parameters: This method does not accepts any parameter.

Returns: This method returns the numeric value represented by this object after conversion to type float.

Below programs illustrate the Number.floatValue() method:



Program 1:




// Below program demonstrate the
// Number.floatValue() method
public class gfg {
  
    public static void main(String[] args)
    {
  
        // number with integer datatype
        Integer x = new Integer(1785423456);
        // print the value as float
        System.out.println(x.floatValue());
  
        // number with double datatype
        Double y = new Double(97854876);
        // print the value as float
        System.out.println(y.floatValue());
    }
}
Output:
1.78542349E9
9.785488E7

Program 2:




// Below program demonstrate the
// Number.floatValue() method
  
public class gfg {
  
    public static void main(String[] args)
    {
  
        // number with integer datatype
        Integer x = new Integer(456);
        // print the value as float
        System.out.println(x.floatValue());
  
        // number with double datatype
        Double y = new Double(96);
        // print the value as float
        System.out.println(y.floatValue());
    }
}
Output:
456.0
96.0

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.




My Personal Notes arrow_drop_up
Recommended Articles
Page :