SjoerdPSV Posted June 20, 2015 Share Posted June 20, 2015 Hello, Could anyone help me, I want to round some numbers in my script to 1 decimal, but I don't know which Lua function I should use for that. For example, 1.36455 will be rounded to 1.4 etc. Link to comment
Walid Posted June 20, 2015 Share Posted June 20, 2015 Try to use math.round function math.round(number, decimals, method) decimals = decimals or 0 local factor = 10 ^ decimals if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor else return tonumber(("%."..decimals.."f"):format(number)) end end Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now