KapKing47Join Date: 2012-09-09 Post Count: 5522 |
how does Roblox Round the Numbers off?
all I can think of is maybe, Convert it into a String and then find the '.' and Numbers after it, then for .floor just takes out the '.' and the Numbers after, for .ceil it would remove the '.' and all the Numbers after it as well, but would do +1 to the Number that they got...
"My Life is going Good... but..." |
|
|
I'm pretty sure those functions are implemented in native Lua, not just Roblox. If that is the case, then go read Lua's source code. |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
mmm... k... feeling lazy to search though Xd
"My Life is going Good... but..." |
|
|
It's probably something super complicated. Don't worry about it. |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
ah well I done it my way XD
u'll be able to check it out soon! XD
"My Life is going Good... but..." |
|
|
In my experience .floor is a lot more accurate than .ceil |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
hmmm
"My Life is going Good... but..." |
|
|
Both are equal in regards to accuracy. Different tasks call for different operations. |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
It's not complicated at all, in fact there are many ways to actually do it. |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
cnt, be my guest, tell me...
1 comes to mind, Divide...
check maybe wat the Numbers after the '.' are and then somehow find a Number that would Neutralize those XD
"My Life is going Good... but..." |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
local floor = num - (num % 1);
num % 1 returns the fractal part (anything after the decimal point) so I just remove it from the main number.
That's probably the easiest way in Lua without using math.floor (the easiest way i can think of right now, at least) |
|
|
function round(num)
num = tostring(num)
local decpattern = "%p%d+$"
local numpattern = "%d+"
local dec = num:match(numpattern)
local num = num:match(numpattern)
dec = tonumber(dec)
num = tonumber(num)
if dec < .5 then
num = num + 1
else
num = num
end
return num
end
print(round(2.85))
-> 3 |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
damnit! XD
am so Stupid! XD
I used String.Manipulation for my math.floor XDDD
Convert to String, then back to, Number XD
"My Life is going Good... but..." |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
No, you really don't want to convert your number into a string then back.
It's better to do number stuff on numbers |
|
|
well i don't know how to do it with math :l |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
lol
"My Life is going Good... but..." |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Look up a couple replies pls |
|
|
that's just floor
i did a rounding function oops |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
lol
"My Life is going Good... but..." |
|
|
also, when do I learn % in school? what subject |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
You probably learned it in elementary school.
Ever done something like this:
5 / 3 = 1 remainder 2 |
|
|
yeah but then we had to do decimals.. which sucks ass.
so what exactly does % do? its been so long since i did that and i think i forgot. |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
It returns the remainder, that's all :) |
|
|
oh dang.. wow
i forgot how to do remainders though.. ugh |
|
KapKing47Join Date: 2012-09-09 Post Count: 5522 |
lol
"My Life is going Good... but..." |
|