DecimalFormat("00.00E0") in Java

Java 8Object Oriented ProgrammingProgramming

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

DecimalFormat decFormat = new DecimalFormat("00.00E0");
System.out.println(decFormat.format(-289.8787));
System.out.println(decFormat.format(8.19));

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("00.00E0");
      System.out.println(decFormat.format(-289.8787));
      System.out.println(decFormat.format(8.19));
      System.out.println(decFormat.format(9897.88));
      System.out.println(decFormat.format(9.9099));
      System.out.println(decFormat.format(12.788));
      System.out.println(decFormat.format(9.678));
   }
}

Output

-28.99E1
81.90E-1
98.98E2
99.10E-1
12.79E0
96.78E-1
raja
Published on 21-Dec-2018 11:06:37
Advertisements