Convert short to double in Java

Tags: double short Convert

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

Assign short variable to double variable

ConvertShortToDoubleExample1.java

public class ConvertShortToDoubleExample1 {
    public static void main(String[] args) {
        short value1 = 100;
        double value2 = value1;

        System.out.println("short value: " + value1);
        System.out.println("double value: " + value2);
    }
}
The output is:
short value: 100
double value: 100.0

Using Double.valueOf() method to instantiate Double from short value

ConvertShortToDoubleExample2.java

public class ConvertShortToDoubleExample2 {
    public static void main(String[] args) {
        short value1 = 55;
        double value2 = Double.valueOf(value1);

        System.out.println("short value: " + value1);
        System.out.println("double value: " + value2);
    }
}
The output is:
short value: 55
double value: 55.0

Using Short.doubleValue() method to return double value of a Short object

ConvertShortToDoubleExample3.java

public class ConvertShortToDoubleExample3 {
    public static void main(String[] args) {
        Short value1 = Short.valueOf((short)20);
        double value2 = value1.doubleValue();

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

Happy Coding 😊