Here you can find the source of truncate(double d, int digits)
public static double truncate(double d, int digits)
//package com.java2s; //License from project: Open Source License import java.text.NumberFormat; public class Main { public static double truncate(double d, int digits) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(digits); nf.setGroupingUsed(false);//ww w . j av a 2 s. com return Double.parseDouble(nf.format(d)); } }