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/ObjectOrientedandAdvancedConceptsGroup(["`Object-Oriented and Advanced Concepts`"]) java(("`Java`")) -.-> java/BasicSyntaxGroup(["`Basic Syntax`"]) java(("`Java`")) -.-> java/StringManipulationGroup(["`String Manipulation`"]) java(("`Java`")) -.-> java/SystemandDataProcessingGroup(["`System and Data Processing`"]) java/ObjectOrientedandAdvancedConceptsGroup -.-> java/packages_api("`Packages / API`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/wrapper_classes("`Wrapper Classes`") java/BasicSyntaxGroup -.-> java/identifier("`Identifier`") java/BasicSyntaxGroup -.-> java/data_types("`Data Types`") java/BasicSyntaxGroup -.-> java/operators("`Operators`") java/BasicSyntaxGroup -.-> java/output("`Output`") java/StringManipulationGroup -.-> java/strings("`Strings`") java/BasicSyntaxGroup -.-> java/variables("`Variables`") java/SystemandDataProcessingGroup -.-> java/system_methods("`System Methods`") subgraph Lab Skills java/packages_api -.-> lab-117648{{"`Java Float doubleValue Method`"}} java/wrapper_classes -.-> lab-117648{{"`Java Float doubleValue Method`"}} java/identifier -.-> lab-117648{{"`Java Float doubleValue Method`"}} java/data_types -.-> lab-117648{{"`Java Float doubleValue Method`"}} java/operators -.-> lab-117648{{"`Java Float doubleValue Method`"}} java/output -.-> lab-117648{{"`Java Float doubleValue Method`"}} java/strings -.-> lab-117648{{"`Java Float doubleValue Method`"}} java/variables -.-> lab-117648{{"`Java Float doubleValue Method`"}} java/system_methods -.-> 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.

Other Java Tutorials you may like