public class Decimal extends BigDecimal
BigDecimal
that can represent negative zeros.
The primary change is the addition of isNegativeZero()
.
WARNING: This class should not be extended by code outside of this library.
This class currently does not have any behavioral difference
from BigDecimal
except for the following:
BigDecimal.toString()
, BigDecimal.toEngineeringString()
, and
BigDecimal.toPlainString()
print a negative sign if necessary.
BigDecimal.floatValue()
and BigDecimal.doubleValue()
return negative zero
results.
BigDecimal.abs()
does the right thing.
equals(java.math.BigDecimal, java.math.BigDecimal)
or BigDecimal.compareTo(java.math.BigDecimal)
so those methods cannot distinguish positive and negative zeros.
It also does not currently override any of the numerical methods,
but it may do so in the future. If you are concerned about
consistent treatment of negative zeros in future releases, you may wish to
use bigDecimalValue(java.math.BigDecimal)
before performing those operations.
Modifier and Type | Field and Description |
---|---|
static Decimal |
NEGATIVE_ZERO
The value -0, with a scale of 0.
|
static Decimal |
ZERO
The value 0, with a scale of 0.
|
ONE, ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_HALF_DOWN, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_UNNECESSARY, ROUND_UP, TEN
Modifier and Type | Method and Description |
---|---|
BigDecimal |
bigDecimalValue()
Converts this to a "plain"
BigDecimal instance, losing any
negative zeros in the process. |
static BigDecimal |
bigDecimalValue(BigDecimal val)
Returns a "plain"
BigDecimal instance, never a Decimal
subclass. |
static boolean |
equals(BigDecimal v1,
BigDecimal v2)
Compares two decimal values for equality, observing both precision and
negative zeros.
|
boolean |
isNegativeZero() |
static boolean |
isNegativeZero(BigDecimal val)
Efficiently determines whether an arbitary decimal value is a negative
zero.
|
static Decimal |
negativeZero(int scale)
Returns a negative-zero decimal value, with the given number of
significant digits (zeros).
|
static Decimal |
negativeZero(int scale,
MathContext mc)
Returns a negative-zero decimal value, with the given number of
significant digits (zeros) and given context.
|
static Decimal |
valueOf(BigDecimal val) |
static Decimal |
valueOf(BigDecimal val,
MathContext mc) |
static Decimal |
valueOf(BigInteger val) |
static Decimal |
valueOf(BigInteger unscaledVal,
int scale) |
static Decimal |
valueOf(BigInteger unscaledVal,
int scale,
MathContext mc) |
static Decimal |
valueOf(BigInteger val,
MathContext mc) |
static Decimal |
valueOf(double val) |
static Decimal |
valueOf(double val,
MathContext mc) |
static Decimal |
valueOf(int val) |
static Decimal |
valueOf(int val,
MathContext mc) |
static Decimal |
valueOf(long val) |
static Decimal |
valueOf(long val,
MathContext mc) |
static Decimal |
valueOf(String val) |
static Decimal |
valueOf(String val,
MathContext mc) |
abs, abs, add, add, byteValueExact, compareTo, divide, divide, divide, divide, divide, divide, divideAndRemainder, divideAndRemainder, divideToIntegralValue, divideToIntegralValue, doubleValue, equals, floatValue, hashCode, intValue, intValueExact, longValue, longValueExact, max, min, movePointLeft, movePointRight, multiply, multiply, negate, negate, plus, plus, pow, pow, precision, remainder, remainder, round, scale, scaleByPowerOfTen, setScale, setScale, setScale, shortValueExact, signum, stripTrailingZeros, subtract, subtract, toBigInteger, toBigIntegerExact, toEngineeringString, toPlainString, toString, ulp, unscaledValue, valueOf
byteValue, shortValue
public static final Decimal ZERO
public static final Decimal NEGATIVE_ZERO
public static boolean isNegativeZero(BigDecimal val)
Decimal
.true
if and only if the value is a negative zero.NullPointerException
- if the value is null
.public static BigDecimal bigDecimalValue(BigDecimal val)
BigDecimal
instance, never a Decimal
subclass. As a side effect, this strips any negative-zero information.val
- may be null.null
if the given value is null
.public static boolean equals(BigDecimal v1, BigDecimal v2)
BigDecimal.equals(Object)
,
which isn't aware of negative zeros, and from
BigDecimal.compareTo(BigDecimal)
, which ignores both precision
and negative zeros.true
if and only if the two BigDecimal
objects
have the same value, scale, and sign.NullPointerException
- if either parameter is null
.public static Decimal negativeZero(int scale)
scale
- the number of significant digits (zeros) after the decimal
point.public static Decimal negativeZero(int scale, MathContext mc)
scale
- the number of significant digits (zeros) after the decimal
point.public static Decimal valueOf(BigInteger unscaledVal, int scale)
public static Decimal valueOf(BigInteger unscaledVal, int scale, MathContext mc)
public static Decimal valueOf(BigInteger val)
public static Decimal valueOf(BigInteger val, MathContext mc)
public static Decimal valueOf(int val)
public static Decimal valueOf(int val, MathContext mc)
public static Decimal valueOf(long val)
public static Decimal valueOf(long val, MathContext mc)
public static Decimal valueOf(double val)
public static Decimal valueOf(double val, MathContext mc)
public static Decimal valueOf(BigDecimal val)
public static Decimal valueOf(BigDecimal val, MathContext mc)
public static Decimal valueOf(String val, MathContext mc)
public final boolean isNegativeZero()
public final BigDecimal bigDecimalValue()
BigDecimal
instance, losing any
negative zeros in the process.BigDecimal
, never a Decimal
.