So as u can tell there are lots of decimals values after the integer 19, How can I only show the integer and not the decimals after it?
Any help Would be greatly appreciated!
![I'M SO HAPPY I COULD SHIT A RAINBOW RIGHT NOW :awesome:](./images/smilies/ms-awesome.png)
Code: Select all
print(math.floor(19.02032))
-- prints "19"
Code: Select all
function print_rounding(number, rounded_number)
print("Rounding " .. tostring(number) .. " to " .. tostring(rounded_number))
end
number1 = 1.72;
rounded_number1 = math.floor(number1 + 0.5)
print_rounding(number1, rounded_number1)
-- prints "Rounding 1.72 to 2"
number2 = 1.45;
rounded_number2 = math.floor(number2 + 0.5)
print_rounding(number2, rounded_number2)
-- prints "Rounding 1.45 to 1"
It's when you round up or down based on if the value's decimal portion is above, below or equals to 0.5. For example, 0.6 would round to 1, and 0.4 would round to 0. On wikipedia, it's called rounding half away from zero. Programming languages or math libraries fairly often tend to have a function for this, but lua's default math library doesn't.
I'd personally just call it by the programming term myself, round half away from zero.This method, also known as commercial rounding,[citation needed] - Wikipedia article
Code: Select all
local str = string.format("Timer: %.1f", t)
Users browsing this forum: Bing [Bot] and 5 guests