DecimalFormat("###E0") in Java


DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. Let us set DecimalFormat("###E0") and use the format() method as well.

DecimalFormat decFormat = new DecimalFormat("##E0");
System.out.println(decFormat.format(-267.9965));
System.out.println(decFormat.format(8.19));
System.out.println(decFormat.format(9897.88));

Since we have used DecimalFormat class in Java, therefore importing the following package is a must −

import java.text.DecimalFormat;

The following is the complete example −

Example

 Live Demo

import java.text.DecimalFormat;
public class Demo {
   public static void main(String[] argv) throws Exception {
      DecimalFormat decFormat = new DecimalFormat("###E0");
      System.out.println(decFormat.format(-267.9965));
      System.out.println(decFormat.format(8.19));
      System.out.println(decFormat.format(9897.88));
      System.out.println(decFormat.format(1.9099));
      System.out.println(decFormat.format(12.788));
      System.out.println(decFormat.format(9.678));
   }
}

Output

-190E0
8.19E0
9.9E3
1.91E0
12.8E0
9.68E0
raja
Published on 21-Dec-2018 11:13:25
Advertisements