What do you want to achieve?
For the percentage calculator to correctly function and return the correct values
What is the issue?
It always returns numbers very slightly over the correct value, im talking like
0.00000000003
Area
3. What solutions have you tried so far?
I got this formula off a formula website, and it seems to be correct, is this just that “Lua can’t really count good” issue or am I doing this wrong?
-- initial function
function MinusPercentage(number, percentage)
local firstnum = percentage / 100
local secondnum = 1 - firstnum
local thirdnum = secondnum * number
return thirdnum
end
--requesting line
print(MinusPercentage(500, 70)) --Should return 150, returns 150.00000000000003
N is the number you are wanting to round such as the 150.00000000000003, also make sure to make the decimal place a value such as the tenth place - 10 , hundredth place - 100, thousandth place - 1000, and so on.
If you don’t want any decimal places you can use this:
-- initial function
function MinusPercentage(number, percentage)
local firstnum = percentage / 100
local secondnum = 1 - firstnum
local thirdnum = secondnum * number
return string.match(thirdnum, "%d+") -- Makes sure it's only a integer
end
--requesting line
print(MinusPercentage(500, 70)) --Should return 150, returns 150.00000000000003
If you want decimal places. You can round like he says.
Find help on math.round here: math
Yes but you also need to multiply in the parenthesis and then divide it by the same number that you multiplied with. I suggest to use a number such as 100000000 because its higher than the ten-thousandth place