Jump to content

Lua division issue


Blueman

Recommended Posts

I was thinking before writing a code and I found a Issue it appears.

If I wrote a code to divide a players money by 40 it would return a decimal in some cases and I need it to be a whole number.

Is there any way to convert a decimal to a whole number in lua. :|

Link to comment

Or just use this function

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 
  
--now use it on any number like this 
math.round(number) 

Link to comment
Not necessarily - your function has 3 arguments, and in the end the scripter is going to have to choose between "ceil" or "floor", the only thing that is slightly more convenient is the decimal option, but for his case he just needs to round to a whole number.

No, the 2 last arguments are optional incase you want to use it ciel or floor leave em blank to use round method.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...