If you have a number, say x = 394.7257, you can round it to a whole number using math.floor/math.ceil. This would give 594/395 depending on what method you used, but is there a way to round a number with a given amount of decimals like math.round(x, 2) = 394.72?
✓ ANSWER ACCEPTED
how do you round a number to a certain amount of decimals?
1 answer
✓ Accepted answer
I use a function similar to this, but this works just the same. This will round a number with a given amount of decimals.
local function Round(number, decimal)
return math.floor(number*(10^decimal)+0.5)/10^decimal
end
You call the function with the number you want to round and the number of decimal places backward you want to go. In your example you would pass the number as "394.7257" and the decimal places back would be 2, so you would call this function like this:
Round(394.7257, 2)
And this will yield the result "394.73" which is technically correct. It would take a bit more work to make a rounding function that factors in significant digits but I think this will work for your purposes.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
well thank you very much