Java.lang.Float.floatValue() Method

Advertisements


Description

The java.lang.Float.floatValue() method returns the float value of this Float object.

Declaration

Following is the declaration for java.lang.Float.floatValue() method

public float floatValue()

Parameters

  • NA

Return Value

This method returns the float value represented by this object.

Exception

  • NA

Example

The following example shows the usage of java.lang.Float.floatValue() method.

package com.tutorialspoint;

import java.lang.*;

public class FloatDemo {

   public static void main(String[] args) {

     // returns the float value represented by this float object
     Float obj = new Float("19.36f");
     float f = obj.floatValue();
     System.out.println("Value = " + f);
    
     obj = new Float("2.00");
     f = obj.floatValue();
     System.out.println("Value = " + f);
   }
}

Let us compile and run the above program, this will produce the following result:

Value = 19.36
Value = 2.0



Advertisements
Advertisements