Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { static int[] s_arPows = new int[] { 1, 10, 100, 1000, 10000 }; public static float round(float sfFloat, int digits) { // Avoiding pow calcs. int multi; if (digits < s_arPows.length) { multi = s_arPows[digits]; } else { multi = (int) Math.pow(10, digits); } return (float) Math.round(sfFloat * multi) / multi; } }