Basically how do I turn 9.12761656 to 9.12? I tried using math.floor but it turns it into an integer. Thanks!
One way would be to multiply it by 100, floor that, then divide it by 100.
9.12761656 * 100 = 912.761656 floor of 912.761656 = 912 912 / 100 = 9.12
Hope this helped
I've seen this question before. Here's a quick problem-solver. I've created a function that rounds a long decimal into a short decimal:
local function decimalRound(num,round) -- Checking if both variables are valid numbers, otherwise throws an error. assert(tonumber(num),"Variable num is not a number.") assert(tonumber(round),"Variable round is not a number.") -- Calculations local result = num local roundNum = 10^round result *= roundNum result = math.floor(result) result /= roundNum -- Return the "result" variable return result end
Example of using decimalRound():
local x = decimalRound(9.12761656,2) print(x)
The following example would return:
9.12
No problem, from Canada. :)