In programming, rounding down to the ones place is important.. think hours to minutes, dollars to change.. etc.
I made a exel spreadsheet that did just that-
in psudocode:
x=5.223
y=rounddown(x) (to the nearest ones place)
x=x-y
print(x..":"..y) |
(in a perfect world would yield 5:0.22)
but when i attempt to round in lua there is no simple round function unlike exel..
math.floor just takes my number to zero
so does this:
function round(num)
if num >= 0 then return math.floor(num+.5)
else return math.ceil(num-.5) end
end |
also yields 0
which i got from
http://lua-users.org/wiki/SimpleRoundFirst, why?
Next, what should i be doing?
“ The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ” - Tom Cargill
Comments
in main.lua (and no other code):
function round(num)
if num >= 0 then return math.floor(num+.5)
else return math.ceil(num-.5) end
end
print(round(2.85))
Result:
main.lua is uploading.
Uploading finished.
3
I use the next code:
[-] Liasoft
edit:
fixed by doing this after your second block of code you posted-
[-] Liasoft