How do I make sure a number is always positive?

I know you can multiply a number by -1 to make it positive, but if it’s already positive sometimes I can’t do anything about that, because I don’t know to check, or always make it positive.

2 Likes
if variable < 0 then
 variable = variable * -1
end

Simple.

Adding on to @Eandvwigle’s solution, you can also do math.abs(x) where “x” is the number. It returns the absolute value of the number (which is always positive).

20 Likes