As the title states, I’m wondering if there’s any way I could, for example, change the number 3.5934509 to only 3.59 (2 decimals)?
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
In your example:
round(3.5934509, 2) --> 3.59
7 Likes
- Multiply it by 100
- Round it using math.floor or math.ceil
- divide it by 100
2 Likes