Number (Json function)
Jump to navigation
Jump to search
Create a Number JSON object (Json class)
[Introduced in Model 204 7.6]
This function creates a Json object of the number type.
Syntax
%json = [%(Json):]Number( number)
Syntax terms
%json | The Json object created by Number. |
---|---|
[%(Json):] | The optional class name in parentheses denotes a virtual constructor. |
number | The numeric value of the new Json object. This value can be returned by the NumberValue function. |
Usage notes
- As with all virtual or true constructors, it is usually not necessary to specify the
%(json):
before the Number method. That is%json = %(json):number(22)
is equivalent to%json = number(22)
. And, because of implicit conversion it is not even necessary to specify the Number method so the previous could be written%json = 22
. - The Number method is probably most useful when its input value has a non-numeric type that is known to be convertible to a number.
Examples
The following example sets a Json object to a number retrieved from a global. This might be a common use case for the Number method as $getg always returns a string.
b $setg('pi', $pi) end b %json is object json %json = number($pi) printText {~=%json} end
This prints:
%json=3.14159265358979