Open In App

Number.floatValue() method in java with examples

Last Updated : 20 Jun, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

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


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 code to demonstrate // Byte floatValue() method cla
2 min read
LongAdder floatValue() method in Java with Examples
LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.floatValue() is an inbuilt method in java that returns the sum as a float value. When the object of the class is created its initial value is zero. Syntax: public float floatValue() Parameters: The function does not accepts any parameter. Return value: The m
2 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. Return Value: The method returns the numeric value repr
1 min read
LongAccumulator floatValue() method in Java with Examples
The java.LongAccumulator.floatValue() is an inbuilt method in java that returns the current value as a float after a widening primitive conversion. Syntax: public float floatValue() Parameters: This method does not accepts any parameter. Return Value: The method returns the current value as a float after a widening primitive conversion. Below progr
2 min read
AtomicInteger floatValue() method in Java with examples
The java.util.concurrent.atomic.AtomicInteger.floatValue() is an inbuilt method in java which returns the current value of the AtomicInteger as a Float data-type after performing primitive conversion. Syntax: public float floatValue() Parameters: The function does not accepts any parameter. Return value: The function returns the numeric value repre
1 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: The function returns the numeric value represented
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 does not accepts any parameter. Return value: The me
2 min read
BigDecimal floatValue() Method in Java with Examples
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 BigD
2 min read
Double floatValue() in Java with Examples
The floatValue() method of Double class is a built-in method to return the value specified by the calling object as float after typecasting. Syntax: DoubleObject.floatValue() Return Type: It returns a float value i.e. the type casted value of the DoubleObject. Example 1: Java Code // Java Program to Implement floatValue() Method // of Double Class
1 min read
Float floatValue() in Java with examples
The floatValue() method in Float Class is a built-in function in java that returns the value specified by the calling object as float after type casting. Syntax: public float floatValue() Return Value: It returns the value of FloatObject as float. Below programs illustrate floatValue() method in Java: Program 1: Java Code // Java code to demonstrat
2 min read
Practice Tags :