Here you can find the source of format(double number)
private static String format(double number)
//package com.java2s; //License from project: Open Source License import java.text.NumberFormat; public class Main { private static String format(double number) { NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); format.setMinimumFractionDigits(0); format.setGroupingUsed(false);//from ww w . j a v a 2 s . com return format.format(number); } }