Here you can find the source of formatDouble(Double num)
public static String formatDouble(Double num)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static String formatDouble(Double num) { String s = formatDouble(num, "#.##"); String[] split = s.split("\\."); String format = ""; char[] chars = split[0].toCharArray(); String append = ""; for (int i = 0; i < chars.length; i++) { append = chars[chars.length - (i + 1)] + append; if ((i + 1) % 3 == 0 || i == chars.length - 1) { format = append + "," + format; append = ""; }//from w ww . j a va 2 s .c o m } String ret = format.substring(0, format.length() - 1); if (split.length > 1) ret += "." + split[1]; return ret; } public static String formatDouble(Double num, String format) { DecimalFormat df = new DecimalFormat(format); return df.format(num); } }