math.abs()

Type Function
Library math.*
Return value Number
Revision Release 2024.3703
Keywords abs, absolute value

Overview

Returns the absolute value (magnitude) of x.

Syntax

math.abs( x )
x (required)

Number. A number.

Examples

local a = math.abs(153)        -- Sets a to 153
local b = math.abs(-15)        -- Sets b to 15
local c = math.abs(12.234)     -- Sets c to 12.234
local d = math.abs(-9.23)      -- Sets d to 9.23