Here you can find the source of priceFormat(float price, String pattern)
public static String priceFormat(float 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);// w w w . j a v a 2s . 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; } }