The # format flag in Java


Apply the # flag to the %o, %x, %e, and %f format specifiers. If you want to display the hexadecimal number with a 0x prefix, then precede the %x specifier with #.

Preceding the %x specifier with a #, the hexadecimal number will be printed with a 0x prefix.

Let us see an example wherein $e is used. It includes a decimal point, even if the decimal digits are not present −

Example

 Live Demo

import java.util.Formatter;
public class Demo {
   public static void main(String args[]) {
      Formatter f = new Formatter();
      System.out.println(f.format("%#e", 5F));
   }
}

Output

5.000000e+00

Updated on: 30-Jul-2019

248 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements