- Author:
- Mark Rotteveel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Decimal128
static final Decimal128
static final Decimal128
static final Decimal128
static final Decimal128
static final Decimal128
-
Method Summary
Modifier and TypeMethodDescriptionstatic Decimal128
parseBytes
(byte[] decBytes) Parses the provided byte array to aDecimal128
.static Decimal128
valueOf
(double value) Creates aDecimal128
fromvalue
, applying rounding where necessary.static Decimal128
valueOf
(double value, OverflowHandling overflowHandling) Creates aDecimal128
fromvalue
, applying rounding where necessary.static Decimal128
Creates aDecimal128
fromvalue
, applying rounding where necessary.static Decimal128
valueOf
(String value, OverflowHandling overflowHandling) Creates aDecimal128
fromvalue
, applying rounding where necessary.static Decimal128
valueOf
(BigDecimal value) Creates aDecimal128
fromvalue
, applying rounding where necessary.static Decimal128
valueOf
(BigDecimal value, OverflowHandling overflowHandling) Creates aDecimal128
fromvalue
, applying rounding where necessary.static Decimal128
valueOf
(BigInteger value) Creates aDecimal128
fromvalue
, applying rounding where necessary.static Decimal128
valueOf
(BigInteger value, OverflowHandling overflowHandling) Creates aDecimal128
fromvalue
, applying rounding where necessary.static Decimal128
Converts a decimal to Decimal128.static Decimal128
valueOf
(Decimal<?> decimal, OverflowHandling overflowHandling) Converts a decimal to Decimal128.static Decimal128
valueOfExact
(BigInteger value) Creates aDecimal128
fromvalue
, rejecting values that would lose precision due to rounding.Methods inherited from class org.firebirdsql.decimal.Decimal
doubleValue, equals, hashCode, toBigDecimal, toBytes, toDecimal, toDecimal, toString
-
Field Details
-
POSITIVE_INFINITY
-
NEGATIVE_INFINITY
-
POSITIVE_NAN
-
NEGATIVE_NAN
-
POSITIVE_SIGNALING_NAN
-
NEGATIVE_SIGNALING_NAN
-
-
Method Details
-
parseBytes
Parses the provided byte array to aDecimal128
.This method parses network byte-order (aka big-endian). When using little-endian order, you will need to reverse the bytes in the array first.
- Parameters:
decBytes
- Bytes of the Decimal128 value in network byte-order (aka big-endian)- Returns:
- Instance of
Decimal128
- Throws:
IllegalArgumentException
- WhendecBytes
is not 16 bytes long
-
valueOf
Creates aDecimal128
fromvalue
, applying rounding where necessary.Values exceeding the range of this type will be returned as +/-Infinity.
- Parameters:
value
- Big decimal value to convert- Returns:
- Decimal128 equivalent
-
valueOf
Creates aDecimal128
fromvalue
, applying rounding where necessary.Values exceeding the range of this type will be handled according to the specified overflow handling.
- Parameters:
value
- Big decimal value to convertoverflowHandling
- Overflow handling to apply- Returns:
- Decimal128 equivalent
- Throws:
DecimalOverflowException
- IfOverflowHandling#THROW_EXCEPTION
and the value is out of range.
-
valueOf
Creates aDecimal128
fromvalue
, applying rounding where necessary.Values exceeding the range of this type will be returned as +/-Infinity.
- Parameters:
value
- Big integer value to convert- Returns:
- Decimal128 equivalent
-
valueOf
Creates aDecimal128
fromvalue
, applying rounding where necessary.Values exceeding the range of this type will be handled according to the specified overflow handling.
Calling this method is equivalent to
valueOf(new BigDecimal(value), overflowHandling)
.- Parameters:
value
- Big integer value to convertoverflowHandling
- Handling of overflows- Returns:
- Decimal128 equivalent
- Throws:
DecimalOverflowException
- IfOverflowHandling#THROW_EXCEPTION
and the value is out of range.- See Also:
-
valueOfExact
Creates aDecimal128
fromvalue
, rejecting values that would lose precision due to rounding.- Parameters:
value
- Big integer value to convert- Returns:
- Decimal128 equivalent
- Throws:
DecimalOverflowException
- If the value is out of range.- See Also:
-
valueOf
Creates aDecimal128
fromvalue
, applying rounding where necessary.Double.NaN
is mapped to positive NaN, the infinities to their equivalent +/- infinity.For normal, finite, values, this is equivalent to
valueOf(BigDecimal.valueOf(value))
.- Parameters:
value
- Double value- Returns:
- Decimal equivalent
-
valueOf
Creates aDecimal128
fromvalue
, applying rounding where necessary.Double.NaN
is mapped to positive NaN, the infinities to their equivalent +/- infinity.For normal, finite, values, this is equivalent to
valueOf(BigDecimal.valueOf(value), overflowHandling)
.- Parameters:
value
- Double valueoverflowHandling
- Overflow handling to apply- Returns:
- Decimal equivalent
- Throws:
DecimalOverflowException
- IfOverflowHandling#THROW_EXCEPTION
and the value is out of range.
-
valueOf
Converts a decimal to Decimal128.For normal, finite, decimals, this behaves like
valueOf(decimal.toBigDecimal())
, seevalueOf(BigDecimal)
.- Parameters:
decimal
- Decimal to convert- Returns:
- Decimal converted to Decimal128, or
decimal
itself if it already is Decimal128
-
valueOf
Converts a decimal to Decimal128.For normal, finite, decimals, this behaves like
valueOf(decimal.toBigDecimal(), overflowHandling)
, seevalueOf(BigDecimal, OverflowHandling)
.- Parameters:
decimal
- Decimal to convertoverflowHandling
- Overflow handling to apply- Returns:
- Decimal converted to Decimal128, or
decimal
itself if it already is Decimal128 - Throws:
DecimalOverflowException
- IfOverflowHandling#THROW_EXCEPTION
and the value is out of range.
-
valueOf
Creates aDecimal128
fromvalue
, applying rounding where necessary.Except for the special values [+/-]Inf, [+/-]Infinity, [+/-]NaN and [+/-]sNaN (case insensitive), the rules of
BigDecimal(String)
apply, with special handling in place to discern between positive and negative zero.Values exceeding the range of this type will be returned as +/-Infinity.
- Parameters:
value
- String value to convert- Returns:
- Decimal equivalent
- Throws:
NumberFormatException
- If the provided string is not valid numeric string.
-
valueOf
Creates aDecimal128
fromvalue
, applying rounding where necessary.Except for the special values [+/-]Inf, [+/-]Infinity, [+/-]NaN and [+/-]sNaN (case insensitive), the rules of
BigDecimal(String)
apply, with special handling in place to discern between positive and negative zero.Values exceeding the range of this type will be handled according to the specified overflow handling.
- Parameters:
value
- String value to convertoverflowHandling
- Overflow handling to apply- Returns:
- Decimal equivalent
- Throws:
NumberFormatException
- If the provided string is not valid numeric string.DecimalOverflowException
- IfOverflowHandling#THROW_EXCEPTION
and the value is out of range.
-