Reputation: 21
Hi everyone i am trying compare integers by getting the amount between them
Lets say that i for example have a base integer
local i = 100
Then i have other integers that are for example 200 and 300.
I want to get the amount between i
and the other to values two see which one is closest to the base integer.
Upvotes: 1
Views: 2645
Reputation: 54589
To get the 'distance' between two integers, you can just compute the absolute difference:
local i = 100
local x = 200
print(math.abs(i - x))
print(math.abs(x - i))
The math.abs
function gets rid of any negative numbers resulting from the subtraction.
Upvotes: 3