Format integer in scientific notation in Java

Description

The following code shows how to format integer in scientific notation.

Example


//from ww  w .  j  a va2  s  .c om
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Main {

  public static void main(String args[]) {
    NumberFormat formatter = new DecimalFormat();

    int maxinteger = Integer.MAX_VALUE;

    formatter = new DecimalFormat("0.######E0");
    System.out.println(formatter.format(maxinteger));

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Data Format »




Java Formatter
Java Number Formatter