Convert byte to double in Java

Tags: double byte Convert

In this Java core tutorial, we learn how to convert byte value into double value in Java via different solutions.

Assign the byte variable to double variable

ConvertByteToDoubleExample1.java

public class ConvertByteToDoubleExample1 {
    public static void main(String[] args) {
        byte value1 = 20;
        double value2 = value1;

        System.out.println("byte value: " + value1);
        System.out.println("double value: " + value2);
    }
}
The output is:
byte value: 20
double value: 20.0

Using Double.valueOf() method to instantiate double from byte value

ConvertByteToDoubleExample2.java

public class ConvertByteToDoubleExample2 {
    public static void main(String[] args) {
        byte value1 = 99;
        double value2 = Double.valueOf(value1);

        System.out.println("byte value: " + value1);
        System.out.println("double value: " + value2);
    }
}
The output is:
byte value: 99
double value: 99.0

Using Byte.doubleValue() method to get Double value of a Byte object

ConvertByteToDoubleExample3.java

public class ConvertByteToDoubleExample3 {
    public static void main(String[] args) {
        Byte value1 = Byte.valueOf((byte) 19);

        double value2 = value1.doubleValue();

        System.out.println("byte value: " + value1);
        System.out.println("double value: " + value2);
    }
}
The output is:
byte value: 19
double value: 19.0

Happy Coding 😊