Here you can find the source of formatDecimal(double number)
public static String formatDecimal(double number)
//package com.java2s; import java.text.NumberFormat; public class Main { public static String formatDecimal(double number) { NumberFormat format = NumberFormat.getInstance(); format.setMaximumIntegerDigits(Integer.MAX_VALUE); format.setMaximumFractionDigits(2); format.setMinimumFractionDigits(2); return format.format(number); }//from w w w . ja v a 2s .c o m public static String formatDecimal(double number, int minFractionDigits, int maxFractionDigits) { NumberFormat format = NumberFormat.getInstance(); format.setMinimumFractionDigits(minFractionDigits); format.setMaximumFractionDigits(minFractionDigits); return format.format(number); } }