Here you can find the source of format(double value)
public static String format(double value)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; import java.math.RoundingMode; import java.text.NumberFormat; public class Main { public static String format(double value) { value = round(value);/*from w ww . j a va 2 s. co m*/ NumberFormat format = NumberFormat.getNumberInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); return format.format(value).replaceAll(",", ""); } public static double round(double value, int scale, RoundingMode roundingMode) { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(scale, roundingMode); double d = bd.doubleValue(); bd = null; return d; } public static double round(double value, int scale) { return round(value, scale, RoundingMode.HALF_EVEN); } public static double round(double value) { return round(value, 2); } }