Here you can find the source of roundDouble(double num, int decimal)
public static String roundDouble(double num, int decimal)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { public static String roundDouble(double num, int decimal) { String s = "0."; for (int i = 0; i < decimal; i++) { s += "0"; }/*w w w . ja v a 2s .c o m*/ NumberFormat f = new DecimalFormat(s); s = f.format(num); return s; } }