PtokaX forum

Development Section => Your Developing Problems => Topic started by: bytecode on 22 October, 2003, 18:43:25

Title: rounding a number?
Post by: bytecode on 22 October, 2003, 18:43:25
I was wondering if anyone can tell me how to round a number using Lua? I'm displaying the current share in terabytes, but cause of the division its a really ugly number with 16 numbers after the decimal place. I'd like to round the number to something a little nicer looking, like 2 numbers after the decimal place, but I can't figure out how.
Title:
Post by: Optimus on 22 October, 2003, 19:00:22
If you paste your script in here, then we can take a look at it.

will not be that hard to realize... 8)
Title:
Post by: bytecode on 22 October, 2003, 19:29:51
Okay, heres the part of the script I'm having problems with:


function NewUserConnected(curUser)
  if (frmHub:GetCurrentShareAmount()/1099511627776 > MaxShare) then
    MaxShare = frmHub:GetCurrentShareAmount()/1099511627776
  end
  if (frmHub:GetUsersCount() > MaxUsers) then
    MaxUsers = frmHub:GetUsersCount()
  end
end

function showstats(userobj)
userobj:SendData(BotName," Largest # of users connected:"..MaxUsers)
userobj:SendData(BotName," Largest total share:"..MaxShare.." TB")
end


Everything works okay, I'd jsut like to be able to round MaxShare to 2 decimal places, cause the division to get it into terabytes makes the number really ugly.
Title:
Post by: c h i l l a on 22 October, 2003, 19:30:21
maybe this

share = format("%.2f",share)
Title:
Post by: bytecode on 23 October, 2003, 00:08:10
thanks, thats exactly what I was looking for.