Java tutorial
//package com.java2s; public class Main { /** * Fix number to 2 decimal places * @param dbl * @return */ public static float fixNumber(double dbl) { int ix = (int) (Math.round(dbl * 100.0)); return ix / 100.0f; } public static double round(double dbl, int decimals) { if (decimals > 8) decimals = 8; double base = Math.pow(10, decimals); int ix = (int) (Math.round(dbl * base)); return ix / base; } }