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: How to round numbers ?

Previous Thread :: Next Thread 
Lego_Figure is not online. Lego_Figure
Joined: 02 Jul 2011
Total Posts: 1536
18 Sep 2016 11:09 AM
I have a script that tells you the current progress in percent that you've done in the obstacle course, it works, but I get numbers like 8.33333333333, is there a way to round these to 8?
Report Abuse
Intern33t is not online. Intern33t
Joined: 19 Nov 2010
Total Posts: 1530
18 Sep 2016 11:20 AM
simple:

math.floor(8.3333333)

hard:

in 8.x, if x >=5 then math.ceil(8.x) else math.floor(8.x)
Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
18 Sep 2016 11:22 AM
or just math.floor(x+.5)


Report Abuse
Intern33t is not online. Intern33t
Joined: 19 Nov 2010
Total Posts: 1530
18 Sep 2016 11:32 AM
rounding 8.1 with your method would yield 8.5, so would 8, but 7.9 would 7.5

very inefficient and misleading
Report Abuse
LuaDeveloped is not online. LuaDeveloped
Joined: 28 Jan 2016
Total Posts: 439
18 Sep 2016 11:35 AM
No it wouldn't it would work better he wants it to round not to floor with math.floor(x+0.5) lets say the number is 7.1- 7.4 it would round to 7 but if the number is 7.5-8.4 it would round to 8
Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
18 Sep 2016 11:59 AM
it rounds to the nearest integer

8.1 -> 8.6 -> 8
8.5 -> 9 -> 9
7.9 -> 8.4 -> 8


Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
18 Sep 2016 12:34 PM
math.floor rounds to the nearest low integer*

math.floor(8) > 8 math.floor(8.5) > 8 math.floor(8.9) > 8 math.floor(9) > 9

math.ceil(8) > 8 math.ceil(8.5) > 9 math.ceil(8.9) > 9 math.ceil(9) > 9

you add 0.5 so that it does this

math.floor(8.7 + 0.5) > 9
(8.7 + 0.5 = 9.2)

to round to a higher number, you do very simple math so that you increase the number so that all of your decimal places will lie inside of the integer

math.floor(num*10+0.5)/10

and to change the amount of places you can use, simply use scientific notation

math.floor(num*(10^Places) + 0.5)/(10^Places)
Report Abuse
Fluffy_Husky is not online. Fluffy_Husky
Joined: 23 May 2016
Total Posts: 763
18 Sep 2016 12:35 PM
to round to a number and maintain decimals*
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