Is there anyway to round up a number to only 2 decimals?

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
  1. Multiply it by 100
  2. Round it using math.floor or math.ceil
  3. divide it by 100
2 Likes