i'd like to negate a number and would like to know if there's a built in method that will convert a negative number to a positive OR a positive into a negative, depending on the number.
i know about Math.abs(), but that only seems to convert negative i开发者_StackOverflow社区nto positive. is there a method that will do both?
Isn't this as simple as multiplying by -1?
var mynum:Number = 5;
mynum = -mynum;
Other options include:
mynum*=-1;
mynum = 0-mynum
Do you need a method? Unary minus should do the trick as in many other languages! If p
> 0, -p
< 0 and viceversa as we learned at school.
精彩评论