SelDraken
(SelDraken)
September 12, 2025, 1:28am
1
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.
ZurichBT
(ZurichBT)
September 12, 2025, 1:37am
2
Does math.abs work for getting rid of the negative? I would recommend trying that.
imbonezs
(bonezs)
September 12, 2025, 1:43am
3
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
avodey
(avocado)
September 12, 2025, 2:10am
5
-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
SelDraken
(SelDraken)
September 12, 2025, 2:16am
6
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
baseparts
(baseparts)
September 12, 2025, 2:42am
8
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
system
(system)
Closed
September 26, 2025, 2:53am
10
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.