SA-MP Forums Archive
Convert a negative number into a positive one - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Convert a negative number into a positive one (/showthread.php?tid=166930)



Convert a negative number into a positive one - AngeldeBlas - 10.08.2010

The title says everything, how can I change a negative number into a positive one?

new ctime = PlayerInfo[targetid][pTimeConnected];
new timeleft = ptime / 60 - 60;

With this, timeleft will be always a negative number in the way I've scripted pTimeConnected. How can I make it positive?


Re: Convert a negative number into a positive one - [HUN]Jaki - 10.08.2010

if (number<0) number=number*-1


Re: Convert a negative number into a positive one - Hiddos - 10.08.2010

pawn Код:
if(timeleft < 0) timeleft *= -1;
Should work.


Re: Convert a negative number into a positive one - AngeldeBlas - 10.08.2010

Thank you very much. It worked.


Re: Convert a negative number into a positive one - Daren_Jacobson - 10.08.2010

pawn Код:
#define abs(%1) \
        (((%1) < 0) ? (-(%1)) : ((%1)))
that will return the positive version of a number and -abs(number) will return the negative

abs(100) == 100
abs(-100) == 100
-abs(-100) == -100
-abs(100) == -100


Re: Convert a negative number into a positive one - Daren_Jacobson - 10.08.2010

"my method" was copied from one of your includes.