|
| 26 Apr 2014 02:24 PM |
How?
So like 58 becomes 60
52 becomes 50
55 becomes 60
1 becomes 0
Not math.floor and math.ceil (which is for decimals to integers) |
|
|
| Report Abuse |
|
|
gijsbel11
|
  |
| Joined: 07 Feb 2009 |
| Total Posts: 4223 |
|
|
| 26 Apr 2014 02:28 PM |
make it a decimal, round it up, make it an integer
example:
n = 10--the magic rounding number a = 73 a = math.floor((56/n)+0.5)*n print(a)
when n = 10 then 'a' will be 70 when n = 100 then 'a' will be 100 when n = 20 then 'a' will be 80
etc...
|
|
|
| Report Abuse |
|
|
| |
|
|
| 26 Apr 2014 02:32 PM |
function roundToTen(x) local str = tostring(x) local lastDig = tonumber(str:sub(str:len(), str:len())) if not lastDig then return false end if lastDig >= 5 then x = x + (10 - lastDig) else x = x - lastDig end return x end
That is what I came up with :P
I tested it and it works. |
|
|
| Report Abuse |
|
|
gijsbel11
|
  |
| Joined: 07 Feb 2009 |
| Total Posts: 4223 |
|
|
| 26 Apr 2014 02:33 PM |
Please don't respond like that, my answer was good.
the 'n' you want is 10 so
function 10round(n) return math.floor(n/10+.5)*10 end
print(10round(27)) -> 30
|
|
|
| Report Abuse |
|
|
gijsbel11
|
  |
| Joined: 07 Feb 2009 |
| Total Posts: 4223 |
|
|
| 26 Apr 2014 02:33 PM |
@TheAltOfDavid12
jesus christ my eyes |
|
|
| Report Abuse |
|
|
yobo89
|
  |
| Joined: 05 Jun 2010 |
| Total Posts: 2341 |
|
|
| 26 Apr 2014 02:34 PM |
| Use the math.floor() method. |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2014 02:34 PM |
^ function names can't start with numbers
Mine works :P |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2014 02:34 PM |
"Please don't respond like that, my answer was good."
That judgement is reserved for the eyes of the OP. |
|
|
| Report Abuse |
|
|
gijsbel11
|
  |
| Joined: 07 Feb 2009 |
| Total Posts: 4223 |
|
|
| 26 Apr 2014 02:37 PM |
@TheAltOfDavid12
SO FINAL ANSWER, THREAD CLOSED, HERE NOTHING TO SEE, EXCEPT FOR OP
function tenround(n) return math.floor(n/10+.5)*10 end
|
|
|
| Report Abuse |
|
|
|
| 26 Apr 2014 02:46 PM |
n = 10 --To the nearest... (E.G: nearest 10th, nearest 100th, etc.) num = 52 --Any number you want to round up or down too.
function RoundNum() number = num/n if tonumber(string.sub(tostring(num), string.len(tostring(n))) < 5 then number = math.ceil(number) * n else number = math.floor(number) * n end return number end
print(RoundNum())
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
gijsbel11
|
  |
| Joined: 07 Feb 2009 |
| Total Posts: 4223 |
|
|
| 26 Apr 2014 02:50 PM |
@Spongocardo,
good answer but it's ugly and way to big so again :
SO, FINAL ANSWER, THREAD CLOSED, HERE NOTHING TO SEE, EXCEPT FOR OP
function tenround(n) return math.floor(n/10+.5)*10 end |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2014 02:52 PM |
@gij GG... XD
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2014 03:04 PM |
Thanks guys. Also I am sorry for my response. I never understood your answer XD
I think I will use TheAltOfDavid12's as it is easy to understand. Thanks! |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2014 03:05 PM |
@war Glad you didn't use mine, mine fails.
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
| |
|
gijsbel11
|
  |
| Joined: 07 Feb 2009 |
| Total Posts: 4223 |
|
|
| 26 Apr 2014 03:05 PM |
@warspyking,
"I think I will use TheAltOfDavid12's as it is easy to understand."
you've got to be kidding me
my answer is like 4 times as small and the working bit is only 1 line. It works 10 times faster and i have to say, mine is actually easier to understand. If you don't understand mine just ask. |
|
|
| Report Abuse |
|
|
|
| 26 Apr 2014 03:07 PM |
@gij Your script may be easier in your eyes, david's script may be easier in his eyes, but OP chose david's as it was easier in his eyes. Mine's just a mess xD
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
gijsbel11
|
  |
| Joined: 07 Feb 2009 |
| Total Posts: 4223 |
|
|
| 26 Apr 2014 03:07 PM |
| Oh and even if you don't understand mine, just use it because it really is better for whole of roblox. |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 26 Apr 2014 03:12 PM |
function Round(number, baseMultiple) return math.floor((number/baseMultiple)+.5)*baseMultiple end
print(Round(4, 10)) --0 print(Round(4, 5)) --5 print(Round(8, 5)) --10 print(Round(7.89, .1) --7.9
This will round to multiples of baseMultiple. If you just want to a certain spot you could use this function:
function Round(number, distanceFromRadix) return math.floor((number/(10^distanceFromRadix)+.5)*(10^distanceFromRadix) end
print(Round(4,1)) --0 print(Round(4,0)) --4 print(Round(8,2)) --0 print(Round(7.89, .1)) --7.9 |
|
|
| Report Abuse |
|
|