How do transform a negative number into a positive number?
Thread | |
---|---|
![]() đ Super Customer đ Posts: 33 âŠī¸ Replies: 42 â¤ī¸ Reactions: 19 |
Jenny Fer
Posted 1668719748 (Edited) (357 views)How do transform a negative number into a positive number?
x = - 7 How to transform a negative number into a positive number or invert the number in Lua GLua for GMod? And then how to have a number always negative I know I'm asking two things. đ |
Replies | |
---|---|
![]() đ¨ Creator đ Posts: 173 âŠī¸ Replies: 79 â¤ī¸ Reactions: 25 |
Norda Scripts Posted 1668721727Try math.abs(-7)
You will always get a positive value, so in your example math.abs(-7)=7. And to convert a positive value back to negative you multiply by -1. So math.abs(7)*-1 will give -7. Same result with math.abs(-7)*-1 = -7 because math.abs will always give a positive value. |
![]() đ Super Customer đ Posts: 33 âŠī¸ Replies: 42 â¤ī¸ Reactions: 19 |
Jenny Fer Posted 1668724217Well done, thank you! I had found a solution was to remove the "-" in string and replace it with a blank "" which leaves the number only. |
![]() đ¨ Creator đ Posts: 173 âŠī¸ Replies: 79 â¤ī¸ Reactions: 25 |
Norda Scripts Posted 1668724549What you have done should work but it is very greedy, math.abs(x) does this kind of job much better. I mark this post as solved. You asked me the question in English and also in French and I am answering you on both forums. Have a nice day. :) |
Sign in or register to reply