Java Float doubleValue Method

JavaJavaBeginner
Practice Now

Introduction

In Java, the doubleValue() is a method of the Float class that returns the numerical equivalent of a Float object after converting it into a double type. This lab will guide you through the steps of using the doubleValue() method in Java.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL java(("Java")) -.-> java/BasicSyntaxGroup(["Basic Syntax"]) java(("Java")) -.-> java/ObjectOrientedandAdvancedConceptsGroup(["Object-Oriented and Advanced Concepts"]) java/BasicSyntaxGroup -.-> java/data_types("Data Types") java/BasicSyntaxGroup -.-> java/variables("Variables") java/BasicSyntaxGroup -.-> java/output("Output") java/BasicSyntaxGroup -.-> java/type_casting("Type Casting") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/classes_objects("Classes/Objects") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/packages_api("Packages / API") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/wrapper_classes("Wrapper Classes") subgraph Lab Skills java/data_types -.-> lab-117648{{"Java Float doubleValue Method"}} java/variables -.-> lab-117648{{"Java Float doubleValue Method"}} java/output -.-> lab-117648{{"Java Float doubleValue Method"}} java/type_casting -.-> lab-117648{{"Java Float doubleValue Method"}} java/classes_objects -.-> lab-117648{{"Java Float doubleValue Method"}} java/packages_api -.-> lab-117648{{"Java Float doubleValue Method"}} java/wrapper_classes -.-> lab-117648{{"Java Float doubleValue Method"}} end

Create a Java class

Create a Java class named FloatDoubleValue using the below command:

touch FloatDoubleValue.java

Import required packages

Import the required package java.lang.Float using the import statement at the beginning of the code:

import java.lang.Float;

Implement the doubleValue() method

Create an instance of Float class and pass a float value to it. Then use the doubleValue() method to convert the Float object to a double type.

Float x = 99.12f;
double i=x.doubleValue();
System.out.println("Equivalent double value is " +i);

Execute the program

Compile the program using the below command:

javac FloatDoubleValue.java

Run the program using the below command:

java FloatDoubleValue

You will see the output on the terminal:

Equivalent double value is 99.12000274658203

Summary

In this lab, you learned how to use the doubleValue() method of the Float class to convert a Float object into its numerical double equivalent. You also learned how to create a Java class, import required packages, implement the doubleValue() method, and execute the Java program in the terminal.