The number of # to the left of the decimal point sets the multiple of the exponent.


import java.text.DecimalFormat;

public class Main {
  public static void main(String[] argv) throws Exception {

    DecimalFormat formatter = new DecimalFormat("#E0"); // exponent can be any
                                                        // value
    String s = formatter.format(-1234.567);
    System.out.println(s);

    s = formatter.format(-.1234567);
    System.out.println(s);
  }
}

Output:


-.1E4
-.1E0

DecimalFormat("##E0") (exponent must be multiple of 2)


import java.text.DecimalFormat;

public class Main {
  public static void main(String[] argv) throws Exception {
    DecimalFormat formatter = new DecimalFormat("##E0");
    String s = formatter.format(-1234.567);
    System.out.println(s);
    s = formatter.format(-123.4567);
    System.out.println(s);
    s = formatter.format(-12.34567);
    System.out.println(s);
  }
}

Output:


-12E2
-1.2E2
-12E0

DecimalFormat("###E0") (exponent must be multiple of 3)


import java.text.DecimalFormat;

public class Main {
  public static void main(String[] argv) {

    DecimalFormat formatter = new DecimalFormat("###E0");
    String s = formatter.format(-1234.567); // -1.23E3
    System.out.println(s);
    s = formatter.format(-123.4567); // -123E0
    System.out.println(s);
    s = formatter.format(-12.34567); // -12.3E0
    System.out.println(s);
    s = formatter.format(-1.234567); // -12.3E0
    System.out.println(s);
    s = formatter.format(-.1234567); // -123E-3
    System.out.println(s);
  }
}
Home 
  Java Book 
    Runnable examples  

Data Type Format:
  1. Decimal Format with different Symbols
  2. 0 symbol shows a digit or 0 if no digit present
  3. Currency value
  4. Decimal separator is set to "|"
  5. Fraction Digits Minimum
  6. Fraction Digits Maximum
  7. Group separators and show trailing zeroes
  8. Leading zeroes
  9. Percentage
  10. Round number to fewer decimals
  11. Scientific notation: 0.######E0 and 0.0E0
  12. . symbol indicates the decimal point
  13. ; symbol specifies an alternate pattern for negative values
  14. ' symbol quotes literal symbols
  15. The number of # to the left of the decimal point sets the multiple of the exponent.
  16. Locale format
  17. Locale US default format
  18. Number Format:0.00
  19. Number Format:#.# (one decimal point)
  20. Number Format:abc#
  21. Number Format:00E00 and 000E00
  22. Number Format:0000000000E0
  23. Number Format:#.###### (more than one decimal point)
  24. Number Format:#.000000
  25. Number Format:.###### (six decimal points)
  26. Number Format:#,###,### (group)
  27. Number Format:##00
  28. Number Format:00.00E0
  29. Number Format:0.######E0
  30. Number Format:000000E0
  31. Parse a string to a number using a NumberFormat