Here you can find the source of trim(int level, double value)
public static double trim(int level, double value)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static double trim(int level, double value) { StringBuilder sb = new StringBuilder("#.#"); for (int i = 0; i < level; i++) sb.append("#"); return Double.valueOf(new DecimalFormat(sb.toString()).format(value)); }/*from ww w .j a va2 s .c o m*/ }