Turning a negative number into a positive in a Number Value

I cant get to make the Debt’s value turn into a positive and add to the Balance value.

Debt value before:
image

Debt value after:
image

I want it so the “-1.5$” could be added to the Balance as soon as the Debt value goes below 0, and the Debt value set back to 0$.

Use the ‘math’ library function named ‘abs’, short for absolute.

math.abs(-1) --1

1 Like

Are you looking for something like this?

balance = 0 -- whatever the balance value is goes here
debt = -1.5 -- whatever the debt is goes here
if debt < 0 then -- if debt is negative
    balance += math.abs(debt) -- here it turns the negative into positive and adds it in balance
    debt = 0
end
print(balance) -- > 1.5
1 Like