Number (Json function)

From m204wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

%jsonThe 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

See also