Java tutorial
//package com.java2s; import java.text.DecimalFormat; import android.util.Log; public class Main { public static double roundTwoDecimals(double d) { try { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(d)); } catch (NumberFormatException nfe) { Log.d("nfe", nfe.toString()); try { int i = (int) (d * 100); d = (i / 100); return d; } catch (NumberFormatException ne) { return d; } } } }