Skip to main content Link Search Menu Expand Document Toggle dark mode Copy Code (external link)

abs() : Absolute Value

Get the absolute value of a number (remove negative sign).


On this page

Signature

abs(value)

Parameters

Parameter Type Required Description
value Number Yes Number to get absolute value of

Returns

Type: Number (same type as input)

The absolute value of the input number.


Examples

Basic Usage

{{abs(-5)}}     <!-- Output: 5 -->
{{abs(5)}}      <!-- Output: 5 -->
{{abs(-3.14)}}  <!-- Output: 3.14 -->

Calculate Difference

<p>Difference: {{abs(model.actual - model.expected)}}</p>

Data:

doc.Params["model"] = new {
    actual = 95,
    expected = 100
};

Output:

<p>Difference: 5</p>

Show Variance

<p>Variance: {{format(abs(model.value - model.average), 'N2')}}</p>

With Conditional

{{#if abs(model.change) > 10}}
  <span class="significant">Significant change</span>
{{/if}}

Notes

  • Works with int, long, double, decimal types
  • Returns same type as input
  • abs(0) returns 0
  • Useful for calculating distances and differences

See Also