How to round a number to 2 decimal places?

How to round a number to 2 decimal places?

For example, if the number is:
0.628321

then it would become:
0.62

1 Like

Hi there! This is how you would achieve this:

local places = 2 -- the amount of decimal places
local number = 0.628321

local mult = 10^places
number=math.floor(number*mult)/mult -- 0.62
7 Likes

With math:

print(math.round(number * 100)/100)

Without math:

print(string.format("%.2f", number))
6 Likes

The way @Volieb mentioned works but I would this module.