Use group separators and show trailing zeroes in Java

Description

The following code shows how to use group separators and show trailing zeroes.

Example


//from w  ww.j  a v a 2s . c  om
import java.text.DecimalFormat;

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

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

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Data Format »




Java Formatter
Java Number Formatter