KGy SOFT

JsonValue Constructor (Double)

KGy SOFT JSON Libraries Help
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.
See the Remarks section for details.

Namespace:  KGySoft.Json
Assembly:  KGySoft.Json (in KGySoft.Json.dll) Version: 2.0.1
Syntax

public JsonValue(
	double value
)

Parameters

value
Type: SystemDouble
The value to initialize the JsonValue from.
Remarks

Caution note Caution
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.
Note Note
  • 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.
See Also

Reference