Package org.bson.types
Class Decimal128
java.lang.Object
java.lang.Number
org.bson.types.Decimal128
- All Implemented Interfaces:
Serializable
,Comparable<Decimal128>
A binary integer decimal representation of a 128-bit decimal value, supporting 34 decimal digits of significand and an exponent range
of -6143 to +6144.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Decimal128
A constant holding a Not-a-Number (NaN) value of typeDecimal128
.static final Decimal128
A constant holding the negative infinity of typeDecimal128
.static final Decimal128
A constant holding a negative Not-a-Number (-NaN) value of typeDecimal128
.static final Decimal128
A constant holding a negative zero value of typeDecimal128
.static final Decimal128
A constant holding the positive infinity of typeDecimal128
.static final Decimal128
A constant holding a positive zero value of typeDecimal128
. -
Constructor Summary
ConstructorDescriptionDecimal128
(long value) Constructs a Decimal128 value representing the given long.Decimal128
(BigDecimal value) Constructs a Decimal128 value representing the given BigDecimal. -
Method Summary
Modifier and TypeMethodDescriptionGets a BigDecimal that is equivalent to this Decimal128.int
double
Converts thisDecimal128
to adouble
.boolean
Returns true if the encoded representation of this instance is the same as the encoded representation ofo
.float
Converts thisDecimal128
to afloat
.static Decimal128
fromIEEE754BIDEncoding
(long high, long low) Create an instance with the given high and low order bits representing this Decimal128 as an IEEE 754-2008 128-bit decimal floating point using the BID encoding scheme.long
getHigh()
Gets the high-order 64 bits of the IEEE 754-2008 128-bit decimal floating point encoding for this Decimal128, using the BID encoding scheme.long
getLow()
Gets the low-order 64 bits of the IEEE 754-2008 128-bit decimal floating point encoding for this Decimal128, using the BID encoding scheme.int
hashCode()
int
intValue()
Converts thisDecimal128
to aint
.boolean
isFinite()
Returns true if this Decimal128 is finite.boolean
Returns true if this Decimal128 is infinite.boolean
isNaN()
Returns true if this Decimal128 is Not-A-Number (NaN).boolean
Returns true if this Decimal128 is negative.long
Converts thisDecimal128
to along
.static Decimal128
Returns a Decimal128 value representing the given String.toString()
Returns the String representation of the Decimal128 value.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
POSITIVE_INFINITY
A constant holding the positive infinity of typeDecimal128
. It is equal to the value return byDecimal128.valueOf("Infinity")
. -
NEGATIVE_INFINITY
A constant holding the negative infinity of typeDecimal128
. It is equal to the value return byDecimal128.valueOf("-Infinity")
. -
NEGATIVE_NaN
A constant holding a negative Not-a-Number (-NaN) value of typeDecimal128
. It is equal to the value return byDecimal128.valueOf("-NaN")
. -
NaN
A constant holding a Not-a-Number (NaN) value of typeDecimal128
. It is equal to the value return byDecimal128.valueOf("NaN")
. -
POSITIVE_ZERO
A constant holding a positive zero value of typeDecimal128
. It is equal to the value return byDecimal128.valueOf("0")
. -
NEGATIVE_ZERO
A constant holding a negative zero value of typeDecimal128
. It is equal to the value return byDecimal128.valueOf("-0")
.
-
-
Constructor Details
-
Decimal128
public Decimal128(long value) Constructs a Decimal128 value representing the given long.- Parameters:
value
- the Decimal128 value represented as a long
-
Decimal128
Constructs a Decimal128 value representing the given BigDecimal.- Parameters:
value
- the Decimal128 value represented as a BigDecimal- Throws:
NumberFormatException
- if the value is out of the Decimal128 range
-
-
Method Details
-
parse
Returns a Decimal128 value representing the given String.- Parameters:
value
- the Decimal128 value represented as a String- Returns:
- the Decimal128 value representing the given String
- Throws:
NumberFormatException
- if the value is out of the Decimal128 range- See Also:
-
fromIEEE754BIDEncoding
Create an instance with the given high and low order bits representing this Decimal128 as an IEEE 754-2008 128-bit decimal floating point using the BID encoding scheme.- Parameters:
high
- the high-order 64 bitslow
- the low-order 64 bits- Returns:
- the Decimal128 value representing the given high and low order bits
-
getHigh
public long getHigh()Gets the high-order 64 bits of the IEEE 754-2008 128-bit decimal floating point encoding for this Decimal128, using the BID encoding scheme.- Returns:
- the high-order 64 bits of this Decimal128
-
getLow
public long getLow()Gets the low-order 64 bits of the IEEE 754-2008 128-bit decimal floating point encoding for this Decimal128, using the BID encoding scheme.- Returns:
- the low-order 64 bits of this Decimal128
-
bigDecimalValue
Gets a BigDecimal that is equivalent to this Decimal128.- Returns:
- a BigDecimal that is equivalent to this Decimal128
- Throws:
ArithmeticException
- if the Decimal128 value is NaN, Infinity, -Infinity, or -0, none of which can be represented as a BigDecimal
-
isNegative
public boolean isNegative()Returns true if this Decimal128 is negative.- Returns:
- true if this Decimal128 is negative
-
isInfinite
public boolean isInfinite()Returns true if this Decimal128 is infinite.- Returns:
- true if this Decimal128 is infinite
-
isFinite
public boolean isFinite()Returns true if this Decimal128 is finite.- Returns:
- true if this Decimal128 is finite
-
isNaN
public boolean isNaN()Returns true if this Decimal128 is Not-A-Number (NaN).- Returns:
- true if this Decimal128 is Not-A-Number
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Decimal128>
-
intValue
public int intValue()Converts thisDecimal128
to aint
. This conversion is analogous to the narrowing primitive conversion fromdouble
toint
as defined in The Java™ Language Specification: any fractional part of thisDecimal128
will be discarded, and if the resulting integral value is too big to fit in aint
, only the low-order 32 bits are returned. Note that this conversion can lose information about the overall magnitude and precision of thisDecimal128
value as well as return a result with the opposite sign. Note that#NEGATIVE_ZERO
is converted to0
. -
longValue
public long longValue()Converts thisDecimal128
to along
. This conversion is analogous to the narrowing primitive conversion fromdouble
tolong
as defined in The Java™ Language Specification: any fractional part of thisDecimal128
will be discarded, and if the resulting integral value is too big to fit in along
, only the low-order 64 bits are returned. Note that this conversion can lose information about the overall magnitude and precision of thisDecimal128
value as well as return a result with the opposite sign. Note that#NEGATIVE_ZERO
is converted to0L
. -
floatValue
public float floatValue()Converts thisDecimal128
to afloat
. This conversion is similar to the narrowing primitive conversion fromdouble
tofloat
as defined in The Java™ Language Specification: if thisDecimal128
has too great a magnitude to represent as afloat
, it will be converted toFloat.NEGATIVE_INFINITY
orFloat.POSITIVE_INFINITY
as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of theDecimal128
value. Note that#NEGATIVE_ZERO
is converted to0.0f
.- Specified by:
floatValue
in classNumber
- Returns:
- this
Decimal128
converted to afloat
. - Since:
- 3.10
-
doubleValue
public double doubleValue()Converts thisDecimal128
to adouble
. This conversion is similar to the narrowing primitive conversion fromdouble
tofloat
as defined in The Java™ Language Specification: if thisDecimal128
has too great a magnitude to represent as adouble
, it will be converted toDouble.NEGATIVE_INFINITY
orDouble.POSITIVE_INFINITY
as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of theDecimal128
value. Note that#NEGATIVE_ZERO
is converted to0.0d
.- Specified by:
doubleValue
in classNumber
- Returns:
- this
Decimal128
converted to adouble
. - Since:
- 3.10
-
equals
Returns true if the encoded representation of this instance is the same as the encoded representation ofo
.One consequence is that, whereas
Double.NaN != Double.NaN
,new Decimal128("NaN").equals(new Decimal128("NaN")
returns true.Another consequence is that, as with BigDecimal,
new Decimal128("1.0").equals(new Decimal128("1.00")
returns false, because the precision is not the same and therefore the representation is not the same. -
hashCode
public int hashCode() -
toString
Returns the String representation of the Decimal128 value.
-