Floating-point hexadecimal in Java


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

310 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements