Java Convert Float to Hexadecimal String

Tags: float Hexadecimal

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

How to convert float to hexadecimal String in Java

In Java, with a given float value we can use the Float.toHexString(float f) static method to convert it to a hexadecimal String as the following Java program.

ConvertFloatToHexExample.java

public class ConvertFloatToHexExample {
    public static void main(String... args) {
        float floatValue = 99;

        // Convert Float to Hexadecimal String
        String hexString = Float.toHexString(floatValue);

        System.out.println("float value: " + floatValue);
        System.out.println("hexadecimal value: " + hexString);
    }
}
The output as below.
float value: 99.0
hexadecimal value: 0x1.8cp6

Happy Coding 😊

Java Convert Float to BigInteger