Floating-point hexadecimal in Java

Java 8Object Oriented ProgrammingProgramming

For Floating-point hexadecimal form, use the %a format specifier.

For Formatter, import the following package −

import java.util.Formatter;

Now create a Formatter object like this −

Formatter f = new Formatter();

Use the format() method for floating-point hexadecimal −

f.format("%a", 298.45)

The following is an example −

Example

 Live Demo

import java.util.Formatter;
public class Demo {
   public static void main(String args[]) {
      Formatter f = new Formatter();
      // Floating-point hexadecimal form
      System.out.println(f.format("%a", 298.45));
   }
}

Output

0x1.2a73333333333p8
raja
Published on 21-Dec-2018 11:40:36
Advertisements