Number (Json function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
No edit summary
 
Line 14: Line 14:
<ul>
<ul>
<li>As with all virtual or true constructors, it is usually not necessary to specify the <code>%(json):</code> before the Number method. That is <code>%json = %(json):number(22)</code> is equivalent to <code>%json = number(22)</code>. And, because of [[Json class#Implicit conversions|implicit conversion]] it is not even necessary to specify the Number method so the previous could be written <code>%json = 22</code>.</li>
<li>As with all virtual or true constructors, it is usually not necessary to specify the <code>%(json):</code> before the Number method. That is <code>%json = %(json):number(22)</code> is equivalent to <code>%json = number(22)</code>. And, because of [[Json class#Implicit conversions|implicit conversion]] it is not even necessary to specify the Number method so the previous could be written <code>%json = 22</code>.</li>
<li>The Number method is probably most useful when its input value has a non-numeric type that is known to be convertable to a number.</li>
<li>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.</li>
</ul>
</ul>



Latest revision as of 21:45, 18 February 2015

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