java.lang.Byte doubleValue()

Description

The doubleValue() method of Byte class returns the value of this Byte as a double after a widening primitive conversion.

Important Notes:

  • The method doubleValue() is specified by doubleValue in class Number.

Method Syntax

public double doubleValue()

Method Argument

Data Type Parameter Description
N/A N/A N/A

Method Returns

The doubleValue() method of Byte class returns the the numeric value represented by this object after conversion to type double.

Compatibility

Requires Java 1.1 and up

Java Byte doubleValue() Example

Below is a simple java example on the usage of doubleValue() method of Byte class.

package com.javatutorialhq.java.examples;

import java.util.Scanner;

/*
 * This example source code demonstrates the use of 
 * doubleValue() method of Byte class.
 */

public class ByteDoubleValueExample {

	public static void main(String[] args) {

		/*
		 * Editor's Note
		 * Be extra careful in using this method
		 * as it uses widening concept
		 */
		
		// ask for user input
		System.out.print("Enter a number:");

		// read the user input
		Scanner s = new Scanner(System.in);
		String value = s.nextLine();
		s.close();
		
		Byte byteValue = new Byte(value);
		// convert byteValue into double
		double result = byteValue.doubleValue();
		
		System.out.println("double value is "+result);

		
	}

}

Basically on the above example, we have asked the user to enter a number on the console. Internally the input value is assign to a Byte object. We then use the doubleValue() method to convert it into type double. It doesn’t do much however it shows the basic behaviour of this method.

Sample Output

Below is the sample output when you run the above example.

java Byte doubleValue() example output