DecimalFormat("0.######E0") in Java

Java 8Object Oriented ProgrammingProgramming

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

new DecimalFormat("0.######E0").format(298757)

Since, we have used DecimalFormat class in Java, therefore importing the following package in 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 {
      System.out.println(new DecimalFormat("0.######E0").format(298757));
      System.out.println(new DecimalFormat("0.######E0").format(19988));
   }
}

Output

2.98757E5
1.9988E4
raja
Published on 21-Dec-2018 06:14:44
Advertisements