Java Convert Double to Hexadecimal String

Tags: double Hexadecimal

In this Java core tutorial we learn how to convert a double value into a hexadecimal String in Java programming language.

How to convert double to hexadecimal in Java

In Java, with a given double value we can use the Double.toHexString(double d) static method to convert it to a hexadecimal String as the following example Java code.

ConvertDoubleToHexExample.java

public class ConvertDoubleToHexExample {
    public static void main(String... args) {
        double doubleValue = 123.99;

        // Convert Double to Hexadecimal String
        String hexString = Double.toHexString(doubleValue);

        System.out.println("Double Value: " + doubleValue);
        System.out.println("Hexadecimal String: " + hexString);
    }
}
The output as below.
Double Value: 123.99
Hexadecimal String: 0x1.eff5c28f5c28fp6

Happy Coding 😊

Java Check Double is Not-a-Number (NaN)

Java Check Double is Infinite Number

Java Check Double is Finite Number

Java Convert Double to BigInteger