Android Utililty Methods Double Round

List of utility methods to do Double Round

Description

The list of methods to do Double Round are organized into topic(s).

Method

Stringround(double d, int decimalPlace)
round
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(decimalPlace);
df.setMinimumFractionDigits(decimalPlace);
return df.format(d);
doubleround(double value)
round
return ((int) (value * 10) / 10.0);
doubleround(double d, int decimalPlace)
round
try {
    BigDecimal bd = new BigDecimal(Double.toString(d));
    bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
    return bd.doubleValue();
} catch (NumberFormatException e) {
    return d;
doubleround(double val, int numberOfDigitsAfterDecimal)
round
double p = (float) Math.pow(10, numberOfDigitsAfterDecimal);
val = val * p;
double tmp = Math.floor(val);
return (double) tmp / p;
doubleround(double what, int howmuch)
round
return (double) ((int) (what * Math.pow(10, howmuch) + .5))
        / Math.pow(10, howmuch);
doubleroundTwoDecimals(double d)
round Two Decimals
DecimalFormat twoDForm = new DecimalFormat("#.##");
return Double.valueOf(twoDForm.format(d));
BigDecimalround(double number, int decimal)
round
return new BigDecimal(number).setScale(decimal,
        BigDecimal.ROUND_HALF_UP);
StringconvertDecimal(double d)
convert Decimal
DecimalFormat df = new DecimalFormat("#.0000");
return df.format(d);
StringtwoDecimalDoubleFormatter(double number)
two Decimal Double Formatter
return String.format("%.2f", number);