Here you can find the source of format(double x, int max, int min)
public static double format(double x, int max, int min)
//package com.java2s; //License from project: Open Source License import java.text.NumberFormat; public class Main { public static double format(double x, int max, int min) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(max); nf.setMinimumFractionDigits(min); try {/* ww w . j av a2 s .c o m*/ Number number = nf.parse(nf.format(x)); x = number.doubleValue(); } catch (Exception e) { e.printStackTrace(); } return x; } }