Template talk:0expr
Documentation
edit{{0expr}}
adds a leading zero to non-negative results < 10 for date calculations.
Usage
edit{{0expr|expression}}
- returns result as is, or 0result for 0 <= result < 10.{{0expr|1=expression}}
- ditto for expressions containing equal signs.
- Updates:
-
- The code was simplified for better support of optional substitution (= no more parameter defaults), hence empty expressions are not more supported.
- Decimal fractions are now kept as is (1.25 results in 01.25), this can be useful for the seconds in timestamps hhmmss.nnn, see ISO 8601.
Example
editCode | Result |
{{0expr|-1}}
|
-1 |
{{0expr|123/100}}
|
01.23 |
{{0expr|1+9}}
|
10 |
{{0expr|not 10}}
|
00 |
{{0expr|1=(7<=8)*9}}
|
09 |
{{0expr|(7<=8)*9|2+3}}
|
05 |
The last example shows that expressions containing "=", "<=", or ">=" won't work directly.
See also
edit- template:0expr (edit•talk•links•history)
- template:Lz3 (edit•talk•links•history) (similar)
- template:Ifdef (edit•talk•links•history) (1= trick)
Discussion
editAdd issues below as you see fit, sign with ~~~~