How to efficiently remove the - from a 0

Trying to do some stuffs with my grid, and I need to access things from a table with a key.

Key being value,value

However sometimes when assigning a key with 0 in one of the values, there is a - added

What would be the most efficient way to remove any -'s from my 0s
Thanks.

Does math.abs work for getting rid of the negative? I would recommend trying that.

Yes, you can do math.abs(number) which returns the absolute value of the number

1 Like

I’m confused as to why Luau is even storing negative zero. Is this a string, or a number? Either way math.abs should work, like they said.

2 Likes

image

-0 and 0 are the same, there’s no reason to fix this. But if you still want to make sure the number is positive, you can use math.abs on it.

1 Like

Sorry, I should have been more specific. I am getting the calculated q and r of a hex grid based on my players location. Then that is converted to a string q..“,”..r

I could use math.abs, but I would have to check with an if, to see if the value was 0, because my string keys will have values with negative.

I just wanted to see what the most efficient way to do this other than just an 'if value == 0 them math.abs, etc…

This is pretty much the most efficient it’s gonna get

Since -0 technically equals 0, do

if Number == 0 then
   Number = 0
end

From my understanding this is the most efficient way

1 Like

had the same issue in the past, just add zero to the value and it will be fixed

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.