-
- All Superinterfaces:
- JsonValue
public interface JsonNumber extends JsonValue
An immutable JSON number value.Implementations may use a
BigDecimal
object to store the numeric value internally. TheBigDecimal
object can be constructed from the following types:
,int
,long
,BigInteger
, anddouble
. Some of the method semantics in this class are defined using theString
BigDecimal
semantics.- Author:
- Jitendra Kotamraju
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.json.JsonValue
JsonValue.ValueType
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description BigDecimal
bigDecimalValue()
Returns this JSON number as aBigDecimal
object.BigInteger
bigIntegerValue()
Returns this JSON number as aBigInteger
object.BigInteger
bigIntegerValueExact()
Returns this JSON number as aBigDecimal
object.double
doubleValue()
Returns this JSON number as adouble
.boolean
equals(Object obj)
Compares the specified object with thisJsonNumber
object for equality.int
hashCode()
Returns the hash code value for thisJsonNumber
object.int
intValue()
Returns this JSON number as anint
.int
intValueExact()
Returns this JSON number as anint
.boolean
isIntegral()
Returns true if this JSON number is a integral number.long
longValue()
Returns this JSON number as along
.long
longValueExact()
Returns this JSON number as along
.String
toString()
Returns a JSON text representation of the JSON number.-
Methods inherited from interface javax.json.JsonValue
getValueType
-
-
-
-
Method Detail
-
isIntegral
boolean isIntegral()
Returns true if this JSON number is a integral number. This method semantics are defined usingbigDecimalValue().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 }
- Returns:
- true if this number is a integral number, otherwise false
-
intValue
int intValue()
Returns this JSON number as anint
. 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.- Returns:
- an
int
representation of the JSON number - See Also:
BigDecimal.intValue()
-
intValueExact
int intValueExact()
Returns this JSON number as anint
.- Returns:
- an
int
representation of the JSON number - Throws:
ArithmeticException
- if the number has a nonzero fractional part or if it does not fit in anint
- See Also:
BigDecimal.intValueExact()
-
longValue
long longValue()
Returns this JSON number as along
. 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.- Returns:
- a
long
representation of the JSON number. - See Also:
BigDecimal.longValue()
-
longValueExact
long longValueExact()
Returns this JSON number as along
.- Returns:
- a
long
representation of the JSON number - Throws:
ArithmeticException
- if the number has a non-zero fractional part or if it does not fit in along
- See Also:
BigDecimal.longValueExact()
-
bigIntegerValue
BigInteger bigIntegerValue()
Returns this JSON number as aBigInteger
object. This is a a convenience method forbigDecimalValue().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.- Returns:
- a
BigInteger
representation of the JSON number. - See Also:
BigDecimal.toBigInteger()
-
bigIntegerValueExact
BigInteger bigIntegerValueExact()
Returns this JSON number as aBigDecimal
object. This is a convenience method forbigDecimalValue().toBigIntegerExact()
.- Returns:
- a
BigInteger
representation of the JSON number - Throws:
ArithmeticException
- if the number has a nonzero fractional part- See Also:
BigDecimal.toBigIntegerExact()
-
doubleValue
double doubleValue()
Returns this JSON number as adouble
. This is a a convenience method forbigDecimalValue().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.- Returns:
- a
double
representation of the JSON number - See Also:
BigDecimal.doubleValue()
-
bigDecimalValue
BigDecimal bigDecimalValue()
Returns this JSON number as aBigDecimal
object.- Returns:
- a
BigDecimal
representation of the JSON number
-
toString
String toString()
Returns a JSON text representation of the JSON number. The representation is equivalent toBigDecimal.toString()
.
-
equals
boolean equals(Object obj)
Compares the specified object with thisJsonNumber
object for equality. Returnstrue
if and only if the type of the specified object is alsoJsonNumber
and theirbigDecimalValue()
objects are equal
-
hashCode
int hashCode()
Returns the hash code value for thisJsonNumber
object. The hash code of aJsonNumber
object is defined as the hash code of itsbigDecimalValue()
object.
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 18/08/2025
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-javaee-rf-javax/json/JsonNumber.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor dieser Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.