Here you can find the source of roundThreeDecimals(double d)
public static double roundThreeDecimals(double d)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static double roundThreeDecimals(double d) { if (Double.isInfinite(d) || Double.isNaN(d)) { return d; }/* ww w . j a v a 2 s.com*/ DecimalFormat threeDForm = new DecimalFormat("#.###"); return Double.valueOf(threeDForm.format(d)); } }