From the reference libraryRedM

autodoc_shared_functions

jo_libs/modules/math/autodoc/autodoc_shared_functions.md

autodoc_shared_functions

Math Functions > math.clamp()

Clamps a number between a minimum and maximum value. <br>

Math Functions > math.clamp() > Syntax

math.clamp(x, min, max)

Math Functions > math.clamp() > Parameters

x : number

The number to clamp

min : number

The minimum value

max : number

The maximum value

Math Functions > math.clamp() > Return Value

Type : number

The clamped number


Math Functions > math.fromHex()

Converts a hexadecimal string to an integer. <br>

Math Functions > math.fromHex() > Syntax

math.fromHex(hex)

Math Functions > math.fromHex() > Parameters

hex : string

The hexadecimal string to convert, with or without "0x" prefix

Math Functions > math.fromHex() > Return Value

Type : integer

The integer representation


Math Functions > math.lerp()

Performs linear interpolation between two values. <br>

Math Functions > math.lerp() > Syntax

math.lerp(a, b, t)

Math Functions > math.lerp() > Parameters

a : number

The starting value

b : number

The ending value

t : number

The interpolation factor, usually between 0 and 1

Math Functions > math.lerp() > Return Value

Type : number

The interpolated value between a and b

Math Functions > math.lerp() > Example

local startValue = 0
local endValue = 100
local factor = 0.5 -- 50% between start and end

local result = math.lerp(startValue, endValue, factor)
print(result) -- Output: 50


Math Functions > math.round()

Rounds a number to the specified decimal precision. <br>

Math Functions > math.round() > Syntax

math.round(number, precision)

Math Functions > math.round() > Parameters

number : number

The number to round

precision : number <BadgeOptional />

The number of decimal places to round to <br> default:0

Math Functions > math.round() > Return Value

Type : number

The rounded number

Math Functions > math.round() > Example

-- Round to nearest whole number (no precision parameter)
local value1 = 3.7
local rounded1 = math.round(value1)
print(rounded1) -- Output: 4

-- Round to specific decimal places
local value2 = 3.14159
local rounded2Decimal = math.round(value2, 2)
print(rounded2Decimal) -- Output: 3.14

local price = 19.9567
local formattedPrice = math.round(price, 2)
print("$" .. formattedPrice) -- Output: $19.95


Math Functions > math.toHex()

Converts a number to hexadecimal string representation. <br>

Math Functions > math.toHex() > Syntax

math.toHex(n, prefix)

Math Functions > math.toHex() > Parameters

n : integer

The integer to convert

prefix : boolean <BadgeOptional />

Add "0x" prefix, default: false

Math Functions > math.toHex() > Return Value

Type : string

The hexadecimal string representation


Math Functions > math.toSigned() > Syntax

math.toSigned(n)
Back to documentation