Android examples for java.math:BigDecimal
round value by BigDecimal
import java.math.BigDecimal; public class Main { public static Object round(Object value, int places) { // if (places < 0) throw new IllegalArgumentException(); if (places < 0 || !(value instanceof Double)) { return value; }// w w w. j a v a 2 s . c o m BigDecimal bd = new BigDecimal((Double) value); bd = bd.setScale(places, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); } }