Reference › Function reference › Functions

Functions.values.round

public

Call as

Functions.values.round(num, numDecimalPlaces)

Record it as a dependency named Functions.values.round (accepting the completion does this), then call it by that name.

What it does

Round with the existing floor(num * 10^places + 0.5) / 10^places formula. Places defaults to zero and may be negative. Halfway negative values round toward positive infinity; no finite-number validation or alternative rounding policy is added.

Arguments

NameTypeWhat it does
numnumberValue passed to the original arithmetic formula.
numDecimalPlacesnumber | nilDecimal places, default zero; negative values round to tens or larger powers of ten.

Returns

1numberOne rounded numeric result from the original formula.

Editions

Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.

It reads no game API directly.

Example

local maximum = UnitHealthMax("target")
if not maximum or maximum == 0 then return nil, "no-target" end
local percent = Functions.values.round(UnitHealth("target") / maximum * 100, 1)
return percent <= 20

Dependencies

Source

Functions/values.lua, line 54. Read only in game; Duplicate makes an editable copy.

Functions.values.round(num, numDecimalPlaces)
    local mult = 10^(numDecimalPlaces or 0)
    return floor(num * mult + 0.5) / mult

Back to Function reference