generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Problem

Previous Thread :: Next Thread 
MADROBOT8886 is not online. MADROBOT8886
Joined: 10 May 2009
Total Posts: 104
04 Jun 2012 06:32 PM
In a game, i am dividing the number of players by 3 (ply/3) and sometimes you get a decimal. For this game i cannot have a decimal number, how do you round a number up or down?
Report Abuse
RA2lover is not online. RA2lover
Joined: 09 Nov 2008
Total Posts: 1254
04 Jun 2012 06:34 PM
math.floor/math.ceil

you can store stuff into IntValues too.
Report Abuse
MADROBOT8886 is not online. MADROBOT8886
Joined: 10 May 2009
Total Posts: 104
04 Jun 2012 06:35 PM
So like:
numplayer/3 = number
math.floor(number) would round it down?
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
04 Jun 2012 06:37 PM
function round(double)
local int , dec = math.modf(double);
if dec > 0.49 then
return int + 1;
end
return int;
end

-- Who needs math.ceil or math.floor?
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
04 Jun 2012 06:50 PM
@nightname, oh god why


>people still don't know this idiom

local function round(n)
return math.floor(n+0.5);
end

Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
04 Jun 2012 06:54 PM
[ Content Deleted ]
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
04 Jun 2012 07:48 PM
@Necro

I said no math.floor or math.ceil.
Report Abuse
NVI is not online. NVI
Joined: 11 Jan 2009
Total Posts: 4744
04 Jun 2012 08:21 PM
Oh god, it took too long for someone to suggest math.floor(x + 0.5).
Report Abuse
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
04 Jun 2012 09:03 PM
@NVI

Ikr? I even know that trick...

~Read Between The Squiggles~
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
04 Jun 2012 09:30 PM
Here's the best way:

n = n - n % 1
i just pwned everyone in this thread with modulus.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
04 Jun 2012 09:31 PM
^ Isn't that just math.floor?
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
04 Jun 2012 09:32 PM
@myrkos

It removes the decimal part of any number. It rounds the number.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
04 Jun 2012 09:35 PM
That doesn't round it. It floors it.

The standard mathematical way of rounding (at least the classic way) is to add 0.5 and then floor it, which results in proper rounding.
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
04 Jun 2012 09:37 PM
@myrkos

There is no such thing as a standard mathematical way of rounding.

Look up 'Rounding' on Wikipedia. There are many ways to round a number.

Rounding can mean many different things. That's the reason there is no rounding function in Lua. There can't be a rounding function in Lua because there are many ways to round a number and they don't all give the same result.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
04 Jun 2012 09:40 PM
I shouldn't have said the standard way, but it is the classic way and the most widely accepted way. There is no reason for Lua not to have added a round function which used the algorithm which seemed to fit best.

Flooring simply is not a rounding method, or at least is a pretty crappy one.
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
04 Jun 2012 09:44 PM
@myrkos

It is a rounding method, just like ceiling is. And that is actually the reason Lua doesn't have a rounding method.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image