new DecimalFormat('0.00') : DecimalFormat « I18N « Java Tutorial






import java.text.DecimalFormat;
import java.text.NumberFormat;

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

    NumberFormat formatter = new DecimalFormat("0.00");
    String s = formatter.format(-.567); // -0.57
    System.out.println(s);
  }
}








13.13.DecimalFormat
13.13.1.new DecimalFormat('0.00')
13.13.2.new DecimalFormat('#.#') two digits
13.13.3.new DecimalFormat('#.######') more digits
13.13.4.new DecimalFormat('.######'), keep fraction
13.13.5.new DecimalFormat('#.000000'), append zero
13.13.6.new DecimalFormat('#,###,###'), group
13.13.7.Arabic DigitsArabic Digits
13.13.8.Format a number with leading zeros
13.13.9.The . symbol indicates the decimal point
13.13.10.The , symbol is used to group numbers
13.13.11.The ; symbol is used to specify an alternate pattern for negative values
13.13.12.The ' symbol is used to quote literal symbols
13.13.13.Use group separators and show trailing zeros
13.13.14.Display numbers in scientific notation
13.13.15.Displaying numbers with commas
13.13.16.new DecimalFormat('##00')
13.13.17.The 0 symbol shows a digit or 0 if no digit present