:IsNumber/doc

Terraria Wiki
둘러보기로 이동 검색으로 이동

This template is used to determine whether an input is an integer number. This is useful in cases where it is ambiguous if, for instance, the value of a template parameter is the name or the ID of an item.

It only recognizes purely numerical strings, i.e., strings consisting of one or more digits. It also recognizes a minus sign in front of the digits (if the $onlypositive parameter is not set). Spaces within the number, or thousands or decimal separators are not considered (spaces around the number are ignored).

Note that it might sometimes be preferable to use a combination of {{#[[[:틀:Tl/parser function links]]##iferror iferror]:}} and {{#[[[:틀:Tl/parser function links]]##expr expr]:}}. That allows recognizing all valid {{#[[[:틀:Tl/parser function links]]##expr expr]:}} syntax, e.g. formulas, which might be useful if the following logic uses {{#[[[:틀:Tl/parser function links]]##expr expr]:}} itself.

Usage

{{ isNumber | <string to check> | onlypositive= y/yes }}

First unnamed parameter

The string which is to be checked if it consists of a number.

onlypositive

Set this parameter to disregard numbers with a minus sign in the front.

Examples

Code Result
{{isNumber|42}} 틀:IsNumber
{{isNumber|forty-two}} 틀:IsNumber
{{isNumber| 42 }} 틀:IsNumber
{{isNumber|4 2}} 틀:IsNumber
{{isNumber|-42}} 틀:IsNumber
{{isNumber|-42|onlypositive=y}} 틀:IsNumber
{{isNumber|- 42}} 틀:IsNumber
{{isNumber|42.1}} 틀:IsNumber
{{isNumber|42,000}} 틀:IsNumber
{{isNumber|42000}} 틀:IsNumber
{{isNumber|}} 틀:IsNumber
{{isNumber|-}} 틀:IsNumber