Template:Ifnumber: Difference between revisions

From Heroes 3 wiki
Jump to navigation Jump to search
(Created page with "<includeonly>{{#ifeq: {{lc:{{{1|}}}}} | e | {{{3|0}}} | {{#iferror:{{#expr:{{{1|}}}*0}}|{{{3|0}}}|{{{2|1}}}}} }}</includeonly><noinclude> Category:Help templates </noinclude>")
 
No edit summary
Line 1: Line 1:
<includeonly>{{#ifeq: {{lc:{{{1|}}}}} | e | {{{3|0}}} | {{#iferror:{{#expr:{{{1|}}}*0}}|{{{3|0}}}|{{{2|1}}}}} }}</includeonly><noinclude>
<includeonly>{{#ifeq: {{lc:{{{1|}}}}} | e | {{{3|0}}} | {{#iferror:{{#expr:{{{1|}}}*0}}|{{{3|0}}}|{{{2|1}}}}} }}</includeonly><noinclude>
=== Usage ===
Returns 1 if the value is numeric and 0 otherwise.
==Examples==
<table class="wikitable">
<tr><th>code</th><th>result</th></tr>
{{template example row|1}}
{{template example row|one}}
{{template example row|<nowiki />}}
{{template example row|e<>pi}}
{{template example row|1|a number|not a number}}
{{template example row|one|a number|not a number}}
{{template example row|1000|a number|not a number}}
{{template example row|10.00|a number|not a number}}
{{template example row|1,000|a number|not a number}}
{{template example row|1,000.50|a number|not a number}}
{{template example row|99 balloons|a number|not a number}}
{{template example row|99.9999e10|a number|not a number}}
{{template example row|&minus;123|a number|not a number}}
{{template example row|(456)|a number|not a number}}
{{template example row|e|a number|not a number}}
<tr><td><code>
<nowiki>{{Ifnumber|{{val|123|5}}|number|value "{{val|123|5}}" not numeric}}</nowiki>&nbsp;</code></td><td> {{Ifnumber|{{val|123|5}}|number|value "{{val|123|5}}" not numeric}}</td>
</tr>
</table>
==Notes==
This template will not recognize formatted numbers, which is by design since formatted numbers will break expression parsers.  To remove the formatting from a number, you can wrap the number first in <nowiki>{{formatnum:</nowiki> ''number'' <nowiki>|R}}</nowiki>.
<table class="wikitable">
<tr><th>code</th><th>result</th></tr>
<tr><td><nowiki>{{</nowiki>{{BASEPAGENAME}}<nowiki>|1,000.50|a number|not a number}}</nowiki></td><td>{{ {{BASEPAGENAME}}|1,000.50|a number|not a number}}</td></tr>
<tr><td><nowiki>{{</nowiki>{{BASEPAGENAME}}<nowiki>|{{formatnum:1,000.50|R}}|a number|not a number}}</nowiki></td><td>{{ {{BASEPAGENAME}}|{{formatnum:1,000.50|R}}|a number|not a number}}</td></tr>
</table>
== See also ==
* {{tl|isnumeric}}
[[Category:Help templates]]
[[Category:Help templates]]
</noinclude>
</noinclude>

Revision as of 17:48, 15 December 2023

Usage

Returns 1 if the value is numeric and 0 otherwise.

Examples

Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row Template:Template example row

coderesult
{{Ifnumber|{{val|123|5}}|number|value "{{val|123|5}}" not numeric}}  value "Template:Val" not numeric

Notes

This template will not recognize formatted numbers, which is by design since formatted numbers will break expression parsers. To remove the formatting from a number, you can wrap the number first in {{formatnum: number |R}}.

coderesult
{{Ifnumber|1,000.50|a number|not a number}}not a number
{{Ifnumber|{{formatnum:1,000.50|R}}|a number|not a number}}a number

See also