This site is supported by donations to The OEIS Foundation.

Template:0expr

From OeisWiki
Jump to: navigation, search

The {{0expr}} date mathematics template evaluates an expression if numeric and prepends a leading zero to a nonnegative result less than 10. An empty expression string returns an empty string.

Usage

{{0expr|expression}}

Examples

Examples with valid input:

{{0expr|{{CURRENTDOW}}}} = 02, whereas {{CURRENTDOW}} = 2
Code Result
{{0expr}}
{{0expr|-1}} -1
{{0expr|123/100}} 01.23
{{0expr|1 + 9}} 10
{{0expr|not 10}} 00
{{0expr|(7 <= 8) * 9}} 09
{{0expr|2 + 3}} 05

Examples with invalid input (see formatted numbers for comma separated numbers like 6,500):

Code Result
{{0expr|6,500}} 0expr error: Argument must be a number (or empty string)
{{0expr|one}} 0expr error: Argument must be a number (or empty string)
{{0expr|3 blobs}} 0expr error: Argument must be a number (or empty string)

Code

<noinclude>{{Documentation}}</noinclude><includeonly><!--
-->{{ifnum| {{#if: {{{1|}}} | {{{1}}} | 0 }}
| {{#if: {{{1|}}}
  | {{ {{{subst|}}}#ifexpr: ( 0 <= {{#expr: ( {{{1}}} ) + 0 }} ) and ( {{#expr: ( {{{1}}} ) + 0 }} < 10 ) | 0 }}<!-- prepend a zero
 -->{{ {{{subst|}}}#expr: {{{1}}} }}
  | <!-- 00 --><!-- return empty string -->
  }}
| {{error| 0expr error: Argument must be a number (or empty string) }}
}}</includeonly>

See also