JsonValueAsNumber Property
Namespace: KGySoft.JsonAssembly: KGySoft.Json (in KGySoft.Json.dll) Version: 3.0.0
public double? AsNumber { get; }
Public ReadOnly Property AsNumber As Double?
Get
public:
property Nullable<double> AsNumber {
Nullable<double> get ();
}
member AsNumber : Nullable<float> with get
Property Value
NullableDouble The JavaScript
Number type is
always a
double-precision 64-bit binary format IEEE 754 value,
which is the equivalent of the
double type in C#. It is not recommended to store C#
long and
decimal
types as JavaScript numbers because their precision might be lost silently if the JSON is processed by JavaScript. If you still want to do so use
the
ToJson extension methods or the
CreateNumberUnchecked method.
When getting this property the stored underlying string is converted to a double
so it has the same behavior as a JavaScript Number.
If this JsonValue was created from a C# long or decimal value (see
the ToJson overloads), then this property may return a different value due to loss of precision.
This is how JavaScript also behaves. To get the value as specific .NET numeric types use the extension methods in the JsonValueExtensions class.
To retrieve the stored actual raw value without any conversion you can use the AsLiteral property.
This property may return if this instance was created by the CreateNumberUnchecked
method and contains an invalid number.
This property can also return when a NaN or Infinity/-Infinity was parsed, which are not valid in JSON.
But even such values can be retrieved as a double by the AsDouble extension method.