JsonValue(Double) Constructor
Initializes a new
JsonValue struct that represents a number.
An implicit conversion from the
double type also exists.
Some .NET numeric types such as
long and
decimal are not recommended to be encoded as JSON numbers.
Use the
ToJson extension methods if you still want to do so.
Namespace: KGySoft.JsonAssembly: KGySoft.Json (in KGySoft.Json.dll) Version: 3.0.0
public JsonValue(
double value
)
Public Sub New (
value As Double
)
public:
JsonValue(
double value
)
new :
value : float -> JsonValue
Parameters
- value Double
- The value to initialize the JsonValue from.
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.
- JavaScript Number type is actually a double. Other large numeric types ([u]long/decimal) must be encoded as string to
prevent loss of precision at a real JavaScript side. If you are sure that you want to forcibly treat such types as numbers use
the ToJson overloads and pass to their asString parameter.
You can use also the CreateNumberUnchecked method to create a JSON number directly from a string.
- This method allows NaN and PositiveInfinity/NegativeInfinity,
which are also invalid in JSON. Parsing these values works though their Type will be UnknownLiteral after parsing.