Number (Json function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
 
No edit summary
Line 1: Line 1:
{{Template:Json:Number subtitle}}
{{Template:Json:Number subtitle}}
 
This function creates a Json object of the number type.
This page is [[under construction]].
==Syntax==
==Syntax==
{{Template:Json:Number syntax}}
{{Template:Json:Number syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%json</th><td><var>Json</var> object</td></tr>
<tr><th>%json</th><td>The <var>Json</var> object created by Number.</td></tr>
<tr><th nowrap="true"><var>[%(Json):]</var></th>
<tr><th nowrap="true"><var>[%(Json):]</var></th>
<td>The optional class name in parentheses denotes a [[Notation conventions for methods#Constructors|virtual constructor]]. See [[#Usage notes|"Usage notes"]], below, for more information about invoking a virtual constructor.</td></tr>
<td>The optional class name in parentheses denotes a [[Notation conventions for methods#Constructors|virtual constructor]].</td></tr>
<tr><th>number</th>
<tr><th>number</th>
<td>number</td></tr>
<td>The numeric value of the new Json object. This value can be returned by the [[NumberValue (Json function)|NumberValue function]].</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<li>As with all virtual or true constructors, it is usually not necessary to specify the <code>%(json):</code> before the Numer 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>
</ul>
==Examples==
==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.
<p class="code">b
$setg('pi', $pi)
end
b
%json is object json
%json = number($pi)
printText {~=%json}
end
</p>
This prints:
<p class="code">%json=3.14159265358979
</p>
==See also==
==See also==
{{Template:Json:Number footer}}
{{Template:Json:Number footer}}

Revision as of 18:52, 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 Numer 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 convertable 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