F Feanor Active member Oct 14, 2020 #1 How can I get an absolute value? Something like {{ abs(-10) }} doesn't work. Do I have to use an if statement and then multiply by negative 1 if < 0?
How can I get an absolute value? Something like {{ abs(-10) }} doesn't work. Do I have to use an if statement and then multiply by negative 1 if < 0?
Solution Mike Oct 14, 2020 I don't think we expose this directly, so yes, you would have to do it conditionally.
Mike XenForo developer Staff member Oct 14, 2020 #2 I don't think we expose this directly, so yes, you would have to do it conditionally. Upvote 0 Downvote Solution
smozgur Well-known member Oct 14, 2020 #3 I know xf:if could be used but setting the current value of the variable by using xf:set might be more useful if the variable will be always used as an absolute value in the template. <xf:set var="$myVar" value="{{(($myVar >= 0 )?:-1) * $myVar }}"/> Upvote 0 Downvote
I know xf:if could be used but setting the current value of the variable by using xf:set might be more useful if the variable will be always used as an absolute value in the template. <xf:set var="$myVar" value="{{(($myVar >= 0 )?:-1) * $myVar }}"/>