Here you can find the source of format(Double num)
public static String format(Double num)
//package com.java2s; //License from project: LGPL import java.math.BigDecimal; import java.text.DecimalFormat; public class Main { static String numericFormat = "#,##0.00"; public static String format(Double num) { String result = ""; try {/*from w w w .ja v a 2s . c om*/ result = new DecimalFormat(numericFormat).format(num); } catch (Exception e) { // TODO: handle exception } return result; } public static String format(Integer num) { String result = ""; try { result = format((double) num); } catch (Exception e) { // TODO: handle exception } return result; } public static String format(String num) { String result = ""; try { result = format(Double.parseDouble(num)); } catch (Exception e) { // TODO: handle exception } return result; } public static String format(BigDecimal num) { String result = ""; try { result = format(num.doubleValue()); } catch (Exception e) { // TODO: handle exception } return result; } }