abs

Modified on Thu, 9 Jul at 10:48 AM

abs

TABLE OF CONTENTS

Find the absolute value of the argument

Definition

number abs(number $value)

If $value is a number, returns the absolute value of the argument, equal to $value if $value is greater or equal to zero, and -$value if $value is less or equal to zero.

Parameters

number $value

Number to calculate the absolute value of.

Returns

number

A number greater or equal to zero, the absolute value of $value.

Examples

Transformation
{
  negativeNum: abs(`-1`),
  positiveNum: abs(`2`),
  stringNum: abs(`3.0`),
  truth: abs(`true`),
  falsity: abs(`false`),
  none: abs(`null`),
  text: abs(`"text"`),     // Error
  array: abs(`[]`),        // Error
  object: abs(`{}`)        // Error
}
Result
{
  "negativeNum": 1,
  "positiveNum": 2,
  "stringNum": 3.0,
  "truth": 1.0,
  "falsity": 0.0,
  "none": 0.0
}

Remarks

Accepts Boolean, null and strings with correct number format arguments as well, in which case the argument is converted to number implicitly before calculating the absolute value. Other argument types raise an Error and return null.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article