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: Round to the nearest 5

Previous Thread :: Next Thread 
doneyes is online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
23 Apr 2017 02:38 PM
This is probably an easy answer but I can't figure it out for some reason.

Input 36 -> output 35

44 -> 45

23 -> 25

12 -> 10

How would I get this? I'm trying a mix of using remainders and using math.floor and can't get it working quite right.
Report Abuse
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
23 Apr 2017 02:39 PM
math.floor
Report Abuse
doneyes is online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
23 Apr 2017 02:44 PM
Why bother posting lol
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
23 Apr 2017 02:45 PM
function RoundToNearst(number, base)
return math.floor(number/base+.5)*base
end
Report Abuse
doneyes is online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
23 Apr 2017 02:46 PM
@casualist

thanks!
Report Abuse
GrantKingABC is not online. GrantKingABC
Joined: 12 Mar 2017
Total Posts: 5
23 Apr 2017 02:50 PM
function RoundToNearestFive(Input)
for Multiple = 0, math.huge, 5 do
if Input == Multiple then
return Input -- Or Multiple
elseif Input > Multiple and (Input - Multiple) < 5 and (Input - Multiple) < ((Multiple + 5) - Input) then
return Multiple
elseif Input > Multiple and (Input - Multiple) < 5 and (Input - Multiple) > ((Multiple + 5) - Input) then
return Multiple + 5
end
end
end
print(RoundToNearestFive(36))
I tested this out in Studio, and it works.
Report Abuse
GrantKingABC is not online. GrantKingABC
Joined: 12 Mar 2017
Total Posts: 5
23 Apr 2017 02:52 PM
VHAT (German "What!?")
Casualist's response works?
I spent 10 minutes on that mess of if statements ^
It was a learning experience, I suppose
Report Abuse
AlreadyPro is not online. AlreadyPro
Joined: 24 Feb 2012
Total Posts: 2463
23 Apr 2017 02:54 PM
was is what in german


Report Abuse
doneyes is online. doneyes
Joined: 21 Mar 2008
Total Posts: 3466
23 Apr 2017 03:14 PM
But it's always read in with the english pronunciation first which really makes it lose its effect
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