ଛାଞ୍ଚ ଆଲୋଚନା:0expr
Documentation
[ସମ୍ପାଦନା]{{0expr}}
adds a leading zero to non-negative results less than 10 for date calculations.
Usage
[ସମ୍ପାଦନା]{{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
[ସମ୍ପାଦନା]Code | 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
[ସମ୍ପାଦନା]Discussion
[ସମ୍ପାଦନା]Add issues below as you see fit, sign with ~~~~
Improved code
[ସମ୍ପାଦନା]I've written an updated code that will handle being passed no parameters (or a blank parameter). Output in such a case will be blank. The improvement is necessary for a template I'm working on and improves the stability of the current template.
{{#if:{{{1|}}}|{{{{{subst|}}}#ifexpr: 0 <= ({{#expr:{{{1}}}+0}}) and ({{#expr:{{{1}}}+0}}) < 10|0}}{{{{{subst|}}}#expr:{{{1}}}}}}}
New examples:
Code | Result |
{{0expr|}}
|
|
{{0expr}}
|
The current result for such cases is an error: update since
Code | Result |
{{0expr|}}
|
|
{{0expr}}
|
Previous test cases still work as expected:
Code | 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 |
--rannpháirtí anaithnid (talk) 12:28, 25 May 2009 (UTC)
p.s. I'd do this myself only I have not been autoconfirmed yet. --rannṗáirtí anaiṫnid (coṁrá) 23:22, 26 May 2009 (UTC)
- Done --rannṗáirtí anaiṫnid (coṁrá) 12:15, 28 May 2009 (UTC)
padleft
[ସମ୍ପାଦନା]Why does this not use the built-in padleft function? --- RockMFR 21:45, 25 July 2009 (UTC)
- The original creator probably didn't know about that function. I didn't when I updated the code (above). Looks like a candidate to be simplified. --rannṗáirtí anaiṫnid (coṁrá) 00:57, 26 July 2009 (UTC)
- Oops. I didn't realize this also supports non-integers. Nevermind. --- RockMFR 01:39, 26 July 2009 (UTC)