@Deprecated public final class DoubleRounder extends Object
DoubleRounder sometimes returns counter-intuitive results. The reason is that it performs mathematically
correct rounding. For instance DoubleRounder.round(256.025d, 2)
will be rounded down to
256.02
because the double value represented as 256.025d
is somewhat smaller than the rational
value 256.025
and hence will be rounded down.
Notes:
BigDecimal(double)
constructor (but not to valueOf(double)
which uses the string
constructor).Constructor and Description |
---|
DoubleRounder(int precision)
Deprecated.
Creates a rounder for the given decimal precision.
|
DoubleRounder(ScaleMetrics scaleMetrics)
Deprecated.
Creates a rounder with the given scale metrics defining the decimal precision.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Deprecated.
Returns true if
obj is a DoubleRounder with the same precision as this rounder instance. |
int |
getPrecision()
Deprecated.
Returns the precision of this rounder, a value between zero and 18.
|
int |
hashCode()
Deprecated.
Returns a hash code for this
DoubleRounder instance. |
double |
round(double value)
Deprecated.
Rounds the given double value to the decimal precision of this rounder using
HALF_UP
rounding. |
static double |
round(double value,
int precision)
Deprecated.
Rounds the given double value to the specified decimal
precision using HALF_UP rounding. |
static double |
round(double value,
int precision,
RoundingMode roundingMode)
Deprecated.
Rounds the given double value to the specified decimal
precision using the specified rounding mode. |
double |
round(double value,
RoundingMode roundingMode)
Deprecated.
Rounds the given double value to the decimal precision of this rounder using the specified rounding mode.
|
String |
toString()
Deprecated.
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()
DoubleRounder
instance.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