Here you can find the source of format(double n)
public static String format(double n)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { private static String currency = "$"; /**/*www . j ava2 s .c om*/ * Formats the given number into a price. Adds commas to enable easy reading and the currency symbol or word * * @return The formatted string. */ public static String format(double n) { //TODO complete NumberFormat formatter; String number; formatter = new DecimalFormat("#,###,###,###.00"); number = formatter.format(n); if (currency.length() == 1) { return currency + number; } else { return number + " " + currency; } } }