开发者

ActionScript Negating a Number

开发者 https://www.devze.com 2023-01-02 10:40 出处:网络
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'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消