Jump to content

math.round


Blinker.

Recommended Posts

Hello ,

i've got no idea why that's not working , it shows on the column "R" the value '4,5012304213' with so much numbers .

i'm using that :

  
setElementData(v,"R",math.round((select[1].r),2) 
  
  

i've tried also tonumber and still not working and no errors in debug ,

thanks in advance.

Link to comment

math.round doesn't seem to exist in original Lua. Use this function:

function math.round(val) 
  return math.ceil(val-0.5) 
end 

You can round this to 2 last diggits like this:

local num = math.round(val*100)/100 

Or just use this function:

function math.round(val,todiggit) 
  local todiggit = todiggit or 0 
  return math.ceil((val-0.5)*(10^todiggit))/(10^todiggit) 
end 

Untested though

Edited by Guest
Link to comment

i've added it already

  
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

Hello ,

sorry i wasn't home , i was on my phone.

@ xXMADEXx i did what u said , i got

Type: number

Value: 0.42857098579407

and no errors in debug

@Dealman

i got number 0 and number 1 and number 2 in scoreboard without period when my ratio increases

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...