Format a number with "$###,###.###" in Java

Description

The following code shows how to format a number with "$###,###.###".

Example


/*from  www  . j  a v a  2 s  .  c  o  m*/
import java.text.DecimalFormat;

public class Main {
  public static void main(String[] argv) {
    DecimalFormat myFormatter = new DecimalFormat("$###,###.###");
    String output = myFormatter.format(123123123.1231231);
    System.out.println(output);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Data Format »




Java Formatter
Java Number Formatter