A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: best way to convert a negative number to positive?

  1. #1
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991

    best way to convert a negative number to positive?

    umm.. hehe.. simply need the easiest way to turn negative numbers into positive..

    i remeber my algebra teacher telling me that if you multiply postive one (+1) with any negative number, the number will become positive..

    however this doesnt seem to be the case with flash..

    real life:
    10 * 1 = 10
    -10 * 1 = 10


    in flash
    10 *1 = 10
    -10 * 1 = -10


  2. #2
    Senior Member
    Join Date
    Oct 2003
    Posts
    1,354
    Shoot your teacher or eat more ginsing...

    Multiply two negatives and you will get a positive.

    -10 * -1 = 10

  3. #3
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    Shoot your teacher or eat more ginsing...

    Multiply two negatives and you will get a positive.

    -10 * -1 = 10
    lol. i think i neeed to eat more ginseng.. my bad.. ..guess it's not good to do math around 3 am in the morning and you're sleepy as heck. lol

    but anyway, i just went ahead and did a condition :

    if(curDifference >100){
    blur.blurX = 100;
    }else{
    blur.blurX = curDifference;
    }

    for code optimizational reasons I was hoping to have a SINGLE LINE of mathematical code to keep my value POSITIVE.. but i guess a simple condition doesnt make much of a difference.

    thanks....for the ginseng suggestion too .lol

  4. #4
    Senior Member
    Join Date
    Oct 2003
    Posts
    1,354
    Not a problem, I had to call up my sister once, she's a math teacher, to remember what they called one of these --> )

    A parenthesis! And I can't stand the taste of ginseng

  5. #5
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    lol...

    we all get stupeed at times.. thanks

  6. #6
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    here is your 1 line solution:
    Code:
    var mynumber = -10;
    mynumber = (mynumber<0) ? (-mynumber) : mynumber;
    trace(mynumber); //traces 10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center