Last modified: 2014-11-18 18:07:31 UTC
A simple expression to handle nonnumbers, negative numbers and nonnegatvie numbers differently: [[hu:User:Tgr/ifexpr]] Here is it in a more legible format: {{#if :{{#ifexpr :{{{1}}} }} |{{{1}}} |{{#ifexpr :{{{1}}}<0 |{{{1}}} |{{{1}}} }} }} The first ifexpr only returns nonempty on error (that is, if the parameter is not a number), thus the first branch of #if is returned if not a number, the first branch of the second #ifexpr if negative, and the second branch if zero or positive. Should obviously return the parameter either way. This works as expexted: [[hu:User vita:Tgr/ifexpr]]. Now lets try separating the is-a-number check and the is-negative check in two different templates: [[hu:Sablon:Ifnumber]] and [[hu:User:Tgr/ifexpr2]]. Check if the first parameter is a number, return the second parameter if true, the third if false: {{#if :{{#ifexpr :{{{1}}} }} |{{{3}}} |{{{2}}} }} Check whether the first parameter is a number using the above, then check for the sign on the true branch: {{ifnumber |{{{1}}} |{{#ifexpr :{{{1}}}<0 |{{{1}}} |{{{1}}} }} |{{{1}}} }} Putting the two together, you get almost the same as the original, except that the two branches of ifnumber are swapped to make parameter order more logical. However, this does NOT work as expected: [[hu:User vita:Tgr/ifexpr2]] It returns "{{{3}}}" (not the third parameter, but the exact text "{{{3}}}") when the first parameter is not a number, as if the third parameter of ifnumber would have gotten lost somehow. Ifnumber works fine in itself; I tried a similar construct with #if instead of #ifexpr, that seemed to work fine too, so I'm guessing this is a bug in #ifexpr somehow.
Seems to be fixed now.