public final class DoubleRounder extends Object
| Constructor and Description |
|---|
DoubleRounder(int precision)
Creates a rounder for the given decimal precision.
|
DoubleRounder(ScaleMetrics scaleMetrics)
Creates a rounder with the given scale metrics defining the decimal precision.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj)
Returns true if
obj is a DoubleRounder with the same precision as this rounder instance. |
int |
getPrecision()
Returns the precision of this rounder, a value between zero and 18.
|
int |
hashCode()
Returns a hash code for this DoubleRounder instance.
|
double |
round(double value)
Rounds the given double value to the decimal precision of this rounder using
HALF_UP
rounding. |
static double |
round(double value,
int precision)
Rounds the given double value to the specified decimal
precision using HALF_UP rounding. |
static double |
round(double value,
int precision,
RoundingMode roundingMode)
Rounds the given double value to the specified decimal
precision using the specified rounding mode. |
double |
round(double value,
RoundingMode roundingMode)
Rounds the given double value to the decimal precision of this rounder using the specified rounding mode.
|
String |
toString()
Returns a string consisting of the simple class name and the precision.
|
public DoubleRounder(int precision)
precision - the decimal rounding precision, must be in [0,18]IllegalArgumentException - if precision is negative or larger than 18public DoubleRounder(ScaleMetrics scaleMetrics)
scaleMetrics - the scale metrics determining the rounding precisionNullPointerException - if scale metrics is nullpublic int getPrecision()
public double round(double value)
HALF_UP
rounding.value - the value to roundgetPrecision()public double round(double value, RoundingMode roundingMode)
value - the value to roundroundingMode - the rounding mode indicating how the least significant returned decimal digit of the result is to be
calculatedgetPrecision()public int hashCode()
public boolean equals(Object obj)
obj is a DoubleRounder with the same precision as this rounder instance.public String toString()
public static final double round(double value, int precision)
precision using HALF_UP rounding.value - the value to roundprecision - the decimal precision to round to (aka decimal places)public static final double round(double value, int precision, RoundingMode roundingMode)
precision using the specified rounding mode.value - the value to roundprecision - the decimal precision to round to (aka decimal places)roundingMode - the rounding mode indicating how the least significant returned decimal digit of the result is to be
calculated