Convert a negative number into a positive one
#1

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?
Reply
#2

if (number<0) number=number*-1
Reply
#3

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

Thank you very much. It worked.
Reply
#5

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
Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)