Java Utililty Methods Decimal Round

List of utility methods to do Decimal Round

Description

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

Method

doubletruncate(double d, int digits)
truncate
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(digits);
nf.setGroupingUsed(false);
return Double.parseDouble(nf.format(d));
doubletruncate(final double v, final int sigNumIndex)
Format the passed in double number by dropping off the less significant numbers so that the least significant number is indicated by the passed in sigNumIndex.
if (sigNumIndex >= 0) {
    return ((int) (v / Math.pow(10, sigNumIndex))) * Math.pow(10, sigNumIndex);
final NumberFormat nf = NumberFormat.getNumberInstance();
nf.setGroupingUsed(false);
nf.setMaximumFractionDigits(Math.abs(sigNumIndex));
return Double.parseDouble(nf.format(v));