Here you can find the source of trunc(double value, int len)
public final static double trunc(double value, int len)
//package com.java2s; //License from project: Apache License public class Main { public final static double trunc(double value, int len) { if (Double.isNaN(value)) { return Double.NaN; }/*from ww w.j a v a2 s . c o m*/ if (Double.isInfinite(value)) { return value; } double p = Math.pow(10, len); if (value > 0) { return (Math.floor(value * p) / p); } else if (value < 0) { return -(Math.floor(-value * p) / p); } else { return 0; } } }