Here you can find the source of truncate(double d)
public static String truncate(double d)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { /** A {@link DecimalFormat} that truncates a decimal to two places. */ public static final DecimalFormat decFormat = new DecimalFormat("#.##"); /** Truncates a double to two places, and makes it a string. */ public static String truncate(double d) { return decFormat.format(d); }//from ww w . j ava2 s . c om }