The # format flag in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 21-Dec-2018 12:05:35
Advertisements