Java.lang.Double.floatValue() Method

Advertisements


Description

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

Declaration

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

public float floatValue()

Parameters

  • NA

Return Value

This method returns the double value represented by this object converted to type float.

Exception

  • NA

Example

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

package com.tutorialspoint;

import java.lang.*;

public class DoubleDemo {

   public static void main(String[] args) {

     // returns the float value of this Double object
     Double obj = new Double("5.60");
     float f = obj.floatValue();
     System.out.println("Value = " + f);
    
     obj = new Double("32");
     f = obj.floatValue();
     System.out.println("Value = " + f);
   }
} 

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

Value = 5.6
Value = 32.0



Advertisements
Advertisements