Here you can find the source of formatDouble(double val, int precision)
public static String formatDouble(double val, int precision)
//package com.java2s; //License from project: Apache License public class Main { public static String formatDouble(double val, int precision) { String format_string = "%1$." + precision + "f"; return String.format(format_string, val); }//from w w w . jav a 2s . c o m }