Author Topic: rounding a number?  (Read 1924 times)

0 Members and 1 Guest are viewing this topic.

Offline bytecode

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
rounding a number?
« 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.

PtokaX forum

rounding a number?
« on: 22 October, 2003, 18:43:25 »

Offline Optimus

  • Emperor
  • **
  • Posts: 1 474
  • Karma: +13/-1
(No subject)
« Reply #1 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)

Offline bytecode

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
(No subject)
« Reply #2 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 MaxSharethen
    MaxShare 
frmHub:GetCurrentShareAmount()/1099511627776
  end
  
if (frmHub:GetUsersCount() > MaxUsersthen
    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.

Offline c h i l l a

  • Lord
  • ***
  • Posts: 347
  • Karma: +1/-0
(No subject)
« Reply #3 on: 22 October, 2003, 19:30:21 »
maybe this

share = format("%.2f",share)

Offline bytecode

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
(No subject)
« Reply #4 on: 23 October, 2003, 00:08:10 »
thanks, thats exactly what I was looking for.

PtokaX forum

(No subject)
« Reply #4 on: 23 October, 2003, 00:08:10 »