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
| Name | Type | What it does |
|---|---|---|
num | number | Value passed to the original arithmetic formula. |
numDecimalPlaces | number | nil | Decimal places, default zero; negative values round to tens or larger powers of ten. |
Returns
| 1 | number | One 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 <= 20Dependencies
floor(builtin:Functions/values.lua:floor)
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