Here you can find the source of trim(int degree, double d)
public static double trim(int degree, double d)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static double trim(int degree, double d) { String format = "#.#"; for (int i = 1; i < degree; i++) { format = format + "#"; }//from w w w . j a va2 s . c o m DecimalFormat twoDForm = new DecimalFormat(format); return Double.valueOf(twoDForm.format(d)).doubleValue(); } }