abs
Returns a number's absolute value.
Parameters
X (number)
The input number.
Examples
ATL in Script | Result |
---|---|
| 500 |
| 500 |
| 15.43 |
This function is useful when using verbs that already denote negativity.
[[ priceDifference = -5.60 changeDirection = priceDifference >= 0 ? 'increased' : 'dropped' joinStrings('The share price ', changeDirection, ' ', priceDifference, '%.') ]]
The output text:
The share price dropped -5.6%.
Here, we don't want the real value because it's negative. The fix is to use the abs
function.
[[
priceDifference = -5.60
changeDirection = priceDifference >= 0 ? 'increased' : 'dropped'
joinStrings('The share price ', changeDirection, ' ', abs(priceDifference), '%.')
]]
The output text:
The share price dropped 5.6%.