Here you can find the source of roundTwoDecimals(double d)
public static double roundTwoDecimals(double d)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static double roundTwoDecimals(double d) { try {//from w w w . j ava 2 s. c om DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(d)); } catch (NumberFormatException e) { return d; } } }