round double value by scale and rounding mode - Android java.lang

Android examples for java.lang:Math

Description

round double value by scale and rounding mode

Demo Code


//package com.java2s;
import java.math.BigDecimal;

public class Main {

    public static double round(double value, int scale, int roundingMode) {
        BigDecimal bd = new BigDecimal(value);
        bd = bd.setScale(scale, roundingMode);
        double d = bd.doubleValue();
        bd = null;//from   w ww.  j ava  2  s.  c o  m
        return d;
    }
}

Related Tutorials