I have a small problem. I want to make a currency converter, but can't figure out how to tackle this problem. Example below:
WhatIHave = 55 WhatIGet = WhatIHave/10 --Output: 5.5
How do I round down WhatIGet
to the lowest whole number (in this case, 5). I don't want to round it up.
You use math.floor
a = 5.5 print(math.floor(a))
And coltn5000, that is just long, you get the same result with
function round(n) return math.floor(n+.5) end print(round(5.6), round(5.4))
5 6
WhatIHave = 55 WhatIGet = math.floor(WhatIHave/10) --Output: 5
math.floor will round it down. (more info)
Do this
function Round(value) if (value%1 > .5) then return math.ceil(value) -- rounds the value up else return math.floor(value) -- rounds the value down end end function Convert(Amount, ReachAmount) -- the amount, and max amount if (Amount >= ReachAmount) then Amount = Amount - ReachAmount -- this will be the amount the person gets if reached to the reach amount return Round(Amount) end end local newAmount = Convert(WhatIHave, 10) print(newAmount) -- print transaction to the output