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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Rounding numbers?

Previous Thread :: Next Thread 
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
11 May 2013 08:36 PM
Is there any way to round a number? I'm having issues with very slightly larger numbers printing with a ridiculous number of digits. It's quite frustrating to read and differentiate, though I don't need to get rid of them.
Report Abuse
StealthKing95 is online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
11 May 2013 08:36 PM
math.floor(0.11) --rounds down to the nearest
math.ceil(0.11) --rounds up to the nearest
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
11 May 2013 08:47 PM
What if the numbers I'm looking for don't round to whole numbers? Is there nothing for that?
Report Abuse
StealthKing95 is online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
11 May 2013 08:53 PM
String manipulation
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
11 May 2013 08:58 PM
I'm afraid I don't follow. A string is a whole different concept from everything I know.
Report Abuse
Aerideyn is not online. Aerideyn
Joined: 16 Jan 2010
Total Posts: 1882
11 May 2013 08:59 PM
then move the decimal point , floor it, then move it back.

function round(number,decimalPoints)
return math.floor(number*10^decimalPoints)+0.5
end
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
11 May 2013 09:02 PM
I figure I could do this with basic math, then. Keep it true to what it is, or some other philosophical malarkey that doesn't really apply.
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
11 May 2013 09:04 PM
Actually, I completely missed what I was asking the second time, thinking about it. I can't just round it to the low or high section, some of the numbers are slightly lower while others are slightly higher. That would set it off by nearly a full stud (or tenth of a stud in this case).
Report Abuse
BJJScrambler is not online. BJJScrambler
Joined: 13 Jan 2013
Total Posts: 898
11 May 2013 09:09 PM
@Aeridyn

Good try, but not quite there.

return math.floor(number*10^decimalPoint+0.5)/10^decimalPoint


You forgot to move and back and implement the 0.5 inside the method.
Report Abuse
Aerideyn is not online. Aerideyn
Joined: 16 Jan 2010
Total Posts: 1882
12 May 2013 01:50 AM
oh yes of course :o
That is what i meant.. just had not had my morning coffee yet XD
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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