abs¶
The abs filter is designed to calculate the absolute value of a number.
Functionality
- Numbers: Takes a numerical value as input (integer or floating-point).
- Absolute Value: Calculates the absolute value, which is the distance of the number from zero. It removes any negative sign and returns the positive magnitude of the number.
- Output: Returns a new numerical value representing the absolute value of the input.
Syntax
ArgumentsThe abs filter does not require any arguments.
Code Samples
Example 1: Absolute Value of a Negative Number
Output: Example 2: Absolute Value of a Positive Number Output: Example 3: Absolute Value of ZeroOutput:
Outliers and Special Cases¶
- Non-Numeric Input: If the input is not a number (e.g., a string or boolean), the
absfilter might attempt to convert it to a number before calculating the absolute value. If the conversion fails, an error might be thrown, depending on Experience Builder's error handling.
Key Points¶
- The
absfilter is a simple but useful tool for mathematical operations within templates. - It is particularly helpful when dealing with values that could be positive or negative, and you only need the magnitude.
- Remember that the original input number is not modified; a new number representing the absolute value is returned.