Here you can find the source of format(double num)
public static String format(double num)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; public class Main { public static String format(double num) { return new DecimalFormat(",###").format(num); }/*from w w w . jav a2s.c om*/ public static String format(double num, int n) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append('0'); } return new DecimalFormat("0." + sb.toString()).format(num); } }