util.math.percent
Shared
Calculates a given percentage of a value
Syntax
local result = util.math.percent(
value,
percent
)Parameters
| Type | Name | Description |
|---|---|---|
float | value | Base number to take a percentage of |
float | percent | Percentage to apply, where 100 represents the full value |
Returns
| Type | Name | Description |
|---|---|---|
float | result | Value scaled by percent/100 |
Examples
local result = util.math.percent(200, 50)
core.engine.print("info", result) -- 100.0local result = util.math.percent(42, 100)
core.engine.print("info", result) -- 42.0local result = util.math.percent(50, 150)
core.engine.print("info", result) -- 75.0local price = 80
local discount = util.math.percent(price, 25)
core.engine.print("info", price - discount) -- 60.0local incoming_damage = 120
local armor_reduction = 35 -- percent
local final_damage = incoming_damage - util.math.percent(incoming_damage, armor_reduction)
core.engine.print("info", final_damage) -- 78.0