This site is supported by donations to The OEIS Foundation.

# Template:Ifnumber

The {{ifnum}}, {{ifnumber}} or {{if number}} if-then-else function template returns {{{2|1}}} if the subject {{{1}}} is a real number, otherwise returns {{{3|0}}}.

If {{{1}}} is

• undefined argument,
• empty string or white space characters (spaces, tabs, newlines) only,
• NAN (not a number, i.e. undefined number),
• INF, +INF or -INF (infinity),

then it is not a [real] number.

The {{is number}} predicate template returns 1 (if true) or 0 (if false).

## Usage

{{ifnum|subject|result if true (optional, default: 1)|result if false (optional, default: 0)}}

or

{{ifnumber|subject|result if true (optional, default: 1)|result if false (optional, default: 0)}}

or

{{if number|subject|result if true (optional, default: 1)|result if false (optional, default: 0)}}

or (as predicate)

{{is number|input}}

## Examples

### Examples where the subject is a number

Code Result Comment
{{is number|0}} 1
{{is number|-0}} 1
{{is number|1}} 1
{{is number|-34}} 1
{{if number|1|a number|not a number}} a number
{{if number|+1000|a number|not a number}} a number
{{if number|10.00|a number|not a number}} a number
{{ifnumber|99.9999e10|a number|not a number}} a number
{{ifnumber|99.9999E10|a number|not a number}} a number
{{ifnum|99.9999e-10|a number|not a number}} a number
{{ifnum|-99.9999e+10|a number|not a number}} a number
{{expr|1 / (2^1024 - 1)}} 0
{{ifnumber|1 / (2^1024 - 1)|a number|not a number}} a number
{{expr|(2^1024 / 2^1024)^0}} 1
{{ifnumber|(2^1024 / 2^1024)^0|a number|not a number}} a number

### Examples where the subject is NOT a number

Code Result Comment
{{is number}} 0
{{is number|}} 0
{{expr|- (2^1024 - 1)}} −INF (Cf. Maximum and minimum numbers allowed)
{{ifnumber|- (2^1024 - 1)|a number|not a number}} not a number
{{expr|+ (2^1024 - 1)}} INF (Cf. Maximum and minimum numbers allowed)
{{ifnumber|+ (2^1024 - 1)|a number|not a number}} not a number
{{is number|one}} 0
{{ifnumber|one|a number|not a number}} not a number
{{ifnumber|99 balloons|a number|not a number}} not a number
{{ifnumber|1,000|a number|not a number}} not a number
{{ifnumber|1,000.50|a number|not a number}} not a number
{{expr|2^1024 - 2^1024}} NAN (undefined number)
{{ifnumber|2^1024 - 2^1024|a number|not a number}} not a number
{{expr|2^1024 / 2^1024}} NAN (undefined number)
{{ifnumber|2^1024 / 2^1024|a number|not a number}} not a number
{{expr|2^1024 + 2^1024 / 2^1024}} NAN (undefined number)
{{ifnumber|2^1024 + 2^1024 / 2^1024|a number|not a number}} not a number
{{is number|nineteen hundred eighty-four}} 0

## Formatted numbers

This template requires unformatted numbers, it will not recognize formatted numbers, e.g. comma separated, 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}}.[1]

Code Result
{{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

## Code

```
<noinclude>{{Documentation}}</noinclude><includeonly><!--

If {{{1}}} is

undefined argument,
empty string or white space characters (spaces, tabs, newlines) only,
NAN (not a number, i.e. undefined number),
INF, +INF or -INF (infinity),

then it is not a [real] number.

-->{{#iferror: {{#expr: {{{1}}} }}
| {{{3|0}}}<!-- {{{1}}} is undefined or not numeric -->
| {{#switch: {{#expr: {{{1}}} }}
| | NAN | INF | +INF | -INF = {{{3|0}}}<!-- {{{1}}} is empty string or white space only string OR {{{1}}} is NAN OR {{{1}}} is +/- INF -->
| #default = {{{2|1}}}<!-- {{{1}}} is a number -->
}}
}}</includeonly>

```