Use group separators and show trailing zeros : DecimalFormat « I18N « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » I18N » DecimalFormat 
13.13.13.Use group separators and show trailing zerosPrevious/Next
import java.text.DecimalFormat;

public class Main {
  public static void main(String[] argvthrows Exception {

    DecimalFormat df = new DecimalFormat("#,.00;(#,.00)");
    System.out.println(df.format(7123.00));

  }
}
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.