Here you can find the source of priceFormat(double price, String pattern)
public static String priceFormat(double price, String pattern)
//package com.java2s; import java.text.DecimalFormat; public class Main { public static String priceFormat(double price, String pattern) { String str = "0"; double anotherNan = Double.NaN; if (Double.compare(price, anotherNan) != 0) { DecimalFormat df1 = new DecimalFormat(pattern); str = df1.format(price);//from w w w . j av a2 s . c o m } else { DecimalFormat df1 = new DecimalFormat(pattern); str = df1.format(str); } return str; } public static String priceFormat(float price, String pattern) { String str = "0"; double anotherNan = Double.NaN; if (Double.compare(price, anotherNan) != 0) { DecimalFormat df1 = new DecimalFormat(pattern); str = df1.format(price); } else { DecimalFormat df1 = new DecimalFormat(pattern); str = df1.format(str); } return str; } }