Here you can find the source of format(double value, double unit)
public static String format(double value, double unit)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; public class Main { public static String format(double value, String pattern) { return new DecimalFormat(pattern).format(value); }//from w w w. j a v a 2s . c o m public static String format(double value, double unit) { int dotIndex = (unit + "").indexOf('.'); if (dotIndex == -1) { return value + ""; } else { int dotDigits = (unit + "").length() - dotIndex - 1; String pattern = "#."; for (int i = 0; i < dotDigits; i++) { pattern += "0"; } return new DecimalFormat(pattern).format(value); } } }