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: Simplistic Round Function

Previous Thread :: Next Thread 
Dynerov is not online. Dynerov
Joined: 21 Jul 2014
Total Posts: 14682
25 Jun 2015 04:37 PM
round = (function(x, base)
local y = x*(10^abs(base-1))
if y - floor(y) >= 0.5 then
return (ceil(y)/abs(10^(base-1)))
else
return (floor(y)/abs(10^(base-1)))
end
end)

It returns the number, and base is technically just how many zeroes it has.

It can go VERY complex with big numbers, or very simple. It could make math.floor and math.ceil obsolete quickly!

Should I call it round10, with the more complex one being roundBase?
Report Abuse
Dynerov is not online. Dynerov
Joined: 21 Jul 2014
Total Posts: 14682
25 Jun 2015 04:40 PM
Feel free to use it. It's a bit heavy, yet I love it because you can customize it.

Here's the more complex (You can divide by numbers that can be different than 10)

And, whoops, it wouldn't work right up yet. Use math. before every math keyword.
Report Abuse
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
25 Jun 2015 04:40 PM
local round = math.floor(initial number + 0.5)
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
25 Jun 2015 04:40 PM
"Simplistic"

#OwnedByAbove

Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784
Report Abuse
025110 is not online. 025110
Joined: 23 Nov 2012
Total Posts: 57661
25 Jun 2015 04:41 PM
function round(x)
return math.floor(x + .5);
end
Report Abuse
Dynerov is not online. Dynerov
Joined: 21 Jul 2014
Total Posts: 14682
25 Jun 2015 04:42 PM
roundBase = (function(x, base)
local y = x*math.abs(base)
if y - math.floor(y) >= 0.5 then
return (math.ceil(y)/math.abs(base))
else
return (math.floor(y)/math.abs(base))
end
end)

round10 = (function(x, base)
local y = x*(10^math.abs(base-1))
if y - math.floor(y) >= 0.5 then
return (math.ceil(y)/math.abs(10^(base-1)))
else
return (math.floor(y)/math.abs(10^(base-1)))
end
end)

Feel free to use them, the roundBase is actually complex yet can be very precise when dividing for certain numbers, and the round10 is simply just rounding by tenths.
Report Abuse
IoIiderp is not online. IoIiderp
Joined: 05 Feb 2012
Total Posts: 8613
25 Jun 2015 04:43 PM
function realisticRound(number)
return"I am not gonna round this number for you, you lazy sack, do it yourself!"
end

What I use in my scripts...
And it works.
Report Abuse
Dynerov is not online. Dynerov
Joined: 21 Jul 2014
Total Posts: 14682
25 Jun 2015 04:43 PM
Well, look, that's simplistic, but mine is actually for variable precision.

You could find 8.92 in 8.9243, or just 8.9, or maybe you want 8.924.
Report Abuse
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
25 Jun 2015 04:46 PM
string manipulation would also work
Report Abuse
murcury57 is not online. murcury57
Joined: 30 Jun 2010
Total Posts: 90299
25 Jun 2015 04:47 PM
[ Content Deleted ]
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
25 Jun 2015 04:49 PM
You can do this:


function round(n, b)
return math.floor(n/b + 0.5) * b
end


If you want to round to the nearest infinity, you could modify it like so:


function round(n, b)
return math.floor(math.abs(n)/b + 0.5)* math.abs(n)/n * b
end


n is the number, b is the base
Report Abuse
Dynerov is not online. Dynerov
Joined: 21 Jul 2014
Total Posts: 14682
25 Jun 2015 04:51 PM
Actually, Geo, I did make an encryption function with string manipulation.

It would be good for giving a top-secret message to someone. But the big problem is, that it can't encrypt symbols.
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