Blitz3D+ Command Reference

CreateJsonNumber ( value:Double )

Parameters

value - the number to store, a finite Double

Description

Creates an owned JSON number from a finite Double.

JSON numbers are binary64 Doubles - the right kind for fractional values like a play-time counter in hours, a difficulty multiplier or a best lap time. NaN and infinity are rejected with a RuntimeError: JSON has no way to represent them, and this constructor refuses to smuggle them in as something else.

Serialization is deterministic and round-trippable: the shortest form that reparses to the identical Double, always keeping a decimal point or exponent so the value stays JSON_NUMBER rather than turning into JSON_INTEGER, and preserving -0.0. That determinism means a document containing numbers can be hashed reliably with Sha256Text.

Read the value back with JsonNumber. The returned handle is owned by you: release it with FreeJson. Container setters copy their input, so the usual pattern is create, set, free.

For the full rules, see the Application Data language reference.

Requires Extended mode.

See also: JsonNumber, CreateJsonInteger, JsonKind, JsonObjectSet, FreeJson.

Example

; CreateJsonNumber Example
; ------------------------
; Requires Extended mode.

; JSON numbers are finite binary64 Doubles - ideal for a play-time
; counter measured in hours (NaN and infinity are rejected)
play_time=CreateJsonNumber(12.75D)

Print "Kind is JSON_NUMBER: "+(JsonKind(play_time)=JSON_NUMBER)
Print "JsonNumber returns:  "+JsonNumber(play_time)
Print ""

; Store it in a save-game record to see it serialized
save=CreateJsonObject()
JsonObjectSet save,"play_time_hours",play_time
Print "In a save file: "+JsonStringify(save,0)

FreeJson save
FreeJson play_time

Print ""
Print "Press any key to close the example"
WaitKey

End

Index