|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface JsonNumber
JsonNumber represents a JSON number value and internally a
BigDecimal may be used to store the numeric value. The BigDecimal
may be constructed using ,
int,
long,
BigInteger and
double.
Some of the method semantics in this class are defined using the
StringBigDecimal semantics.
| Nested Class Summary | |
|---|---|
static class |
JsonNumber.JsonNumberType
JSON number type |
| Nested classes/interfaces inherited from interface javax.json.JsonValue |
|---|
JsonValue.JsonValueType |
| Field Summary |
|---|
| Fields inherited from interface javax.json.JsonValue |
|---|
FALSE, NULL, TRUE |
| Method Summary | |
|---|---|
BigDecimal |
getBigDecimalValue()
Returns JSON number as a BigDecimal |
BigInteger |
getBigIntegerValue()
Returns JSON number as a BigInteger number. |
BigInteger |
getBigIntegerValueExact()
Returns JSON number as a BigDecimal number. |
double |
getDoubleValue()
Returns JSON number as a double number. |
int |
getIntValue()
Returns JSON number as an int number. |
int |
getIntValueExact()
Returns JSON number as an int number. |
long |
getLongValue()
Returns JSON number as a long number. |
long |
getLongValueExact()
Returns JSON number as a long number. |
JsonNumber.JsonNumberType |
getNumberType()
Returns a JSON number type that can hold the number's numeric value. |
String |
toString()
Returns a JSON representation of the JSON number value. |
| Methods inherited from interface javax.json.JsonValue |
|---|
getValueType |
| Method Detail |
|---|
JsonNumber.JsonNumberType getNumberType()
BigDecimal may be used to store the numeric value.
If the scale of a value is non-zero, its number type is
BIG_DECIMAL. If the scale is zero,
and the value is numerically an integer. If the value can be exactly
represented as an int, its type is INT;
if the value can be exactly represented as a long, its type is
LONG; otherwise, its type is
BIG_DECIMAL.
This method can be used to get the holding number type and use that information to invoke appropriate methods to get numeric value for a number.
For example:
switch(getNumberType()) {
case INT :
int i = getIntValue(); break;
case LONG :
long l = getLongValue(); break;
case BIG_DECIMAL :
BigDecimal bd = getBigDecimalValue(); break;
}
int getIntValue()
int number. 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 for JSON number.BigDecimal.intValue()int getIntValueExact()
int number.
int for JSON number
ArithmeticException - cause if the number has a nonzero fractional
part, or will not fit in an intBigDecimal.intValueExact()long getLongValue()
long number. 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 for JSON number.BigDecimal.longValue()long getLongValueExact()
long number.
long for JSON number
ArithmeticException - if the number has a nonzero fractional
part, or will not fit in a long.BigDecimal.longValueExact()BigInteger getBigIntegerValue()
BigInteger number. It is more of
a convenience method for getBigDecimalValue().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.
BigDecimal.toBigInteger()BigInteger getBigIntegerValueExact()
BigDecimal number. It is more of
a convenience method for getBigDecimalValue().toBigIntegerExact().
BigInteger for JSON number
ArithmeticException - if the number has a nonzero fractional part.BigDecimal.toBigIntegerExact()double getDoubleValue()
double number. It is more of
a convenience method for getBigDecimalValue().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 for JSON numberBigDecimal.doubleValue()BigDecimal getBigDecimalValue()
BigDecimal
BigDecimal for JSON numberString toString()
BigDecimal.toString().
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||