public interface JsonNumber extends JsonValue
Implementations may use a BigDecimal object to store the numeric
value internally.
The BigDecimal object can be constructed from the following types:
,
int,
long,
BigInteger, and
double.
Some of the method semantics in this class are defined using the
StringBigDecimal semantics.
JsonValue.ValueType| Modifier and Type | Method and Description |
|---|---|
BigDecimal |
bigDecimalValue()
Returns this JSON number as a
BigDecimal object. |
BigInteger |
bigIntegerValue()
Returns this JSON number as a
BigInteger object. |
BigInteger |
bigIntegerValueExact()
Returns this JSON number as a
BigDecimal object. |
double |
doubleValue()
Returns this JSON number as a
double. |
boolean |
equals(Object obj)
Compares the specified object with this
JsonNumber object for
equality. |
int |
hashCode()
Returns the hash code value for this
JsonNumber object. |
int |
intValue()
Returns this JSON number as an
int. |
int |
intValueExact()
Returns this JSON number as an
int. |
boolean |
isIntegral()
Returns true if this JSON number is a integral number.
|
long |
longValue()
Returns this JSON number as a
long. |
long |
longValueExact()
Returns this JSON number as a
long. |
String |
toString()
Returns a JSON text representation of the JSON number.
|
getValueTypeboolean isIntegral()
bigDecimalValue().scale(). If the
scale is zero, then it is considered integral type. This integral type
information can be used to invoke an appropriate accessor method to
obtain a numeric value as in the following example:
JsonNumber num = ...
if (num.isIntegral()) {
num.longValue(); // or other methods to get integral value
} else {
num.doubleValue(); // or other methods to get decimal number value
}
int intValue()
int. Note that this conversion
can lose information about the overall magnitude and precision of the
number value as well as return a result with the opposite sign.int representation of the JSON numberBigDecimal.intValue()int intValueExact()
int.int representation of the JSON numberArithmeticException - if the number has a nonzero fractional
part or if it does not fit in an intBigDecimal.intValueExact()long longValue()
long. Note that this conversion
can lose information about the overall magnitude and precision of the
number value as well as return a result with the opposite sign.long representation of the JSON number.BigDecimal.longValue()long longValueExact()
long.long representation of the JSON numberArithmeticException - if the number has a non-zero fractional
part or if it does not fit in a longBigDecimal.longValueExact()BigInteger bigIntegerValue()
BigInteger object. This is a
a convenience method for bigDecimalValue().toBigInteger().
Note that this conversion can lose information about the overall
magnitude and precision of the number value as well as return a result
with the opposite sign.BigInteger representation of the JSON number.BigDecimal.toBigInteger()BigInteger bigIntegerValueExact()
BigDecimal object. This is a
convenience method for bigDecimalValue().toBigIntegerExact().BigInteger representation of the JSON numberArithmeticException - if the number has a nonzero fractional partBigDecimal.toBigIntegerExact()double doubleValue()
double. This is a
a convenience method for bigDecimalValue().doubleValue().
Note that this conversion can lose information about the overall
magnitude and precision of the number value as well as return a result
with the opposite sign.double representation of the JSON numberBigDecimal.doubleValue()BigDecimal bigDecimalValue()
BigDecimal object.BigDecimal representation of the JSON numberString toString()
BigDecimal.toString().boolean equals(Object obj)
JsonNumber object for
equality. Returns true if and only if the type of the specified
object is also JsonNumber and their bigDecimalValue()
objects are equalint hashCode()
JsonNumber object. The
hash code of a JsonNumber object is defined as the hash code of
its bigDecimalValue() object.Copyright © 1996-2015, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.