Java tutorial
//package com.java2s; import java.math.BigDecimal; public class Main { public static float roundFloat(Float v, int scale) { if (scale < 0) { throw new IllegalArgumentException( "The scale must be a positive integer or zero"); } BigDecimal b = new BigDecimal(Float.toString(v)); BigDecimal one = new BigDecimal("1"); return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).floatValue(); } }