Home / Forum / Discussion and Help for Gmod-Glua-Lua / How do transform a negative number into a positive number? ✔️ Solved
Thread | |
---|---|
⚗️ Support 📖 Posts: 31 ↩️ Replies: 42 ❤️ Reactions: 18 |
Jenny Fer
Posted 1668719748 (Edited) (129 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. ⛔️ Sorry, you are not connected, join to leave a reaction
|
Replies | |
---|---|
🎨 Creator 📖 Posts: 162 ↩️ Replies: 76 ❤️ 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. |
⚗️ Support 📖 Posts: 31 ↩️ Replies: 42 ❤️ Reactions: 18 |
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: 162 ↩️ Replies: 76 ❤️ 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. :) |