Results 1 to 3 of 3

Thread: (javascript) getting the negative version of a positive number. **Resolved**

  1. #1

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057

    (javascript) getting the negative version of a positive number. **Resolved**

    OK, I know there is a term for this but I never payed attention in school and I'm sure if I knew the term I could look it up myself but since I didnt I have to ask. I need the negative version of a positive number.... for example I have 500 but I need -500. I can easily do it this way (500 - 500 - 500) but I know that is poor, and am sure javascript has a function to do this.
    Thanks
    Michael
    Last edited by msimmons; May 28th, 2002 at 11:51 AM.
    I'm off to GalahTech, hope to see you there.

    If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.

  2. #2

    Thread Starter
    Frenzied Member msimmons's Avatar
    Join Date
    Jul 2001
    Location
    Houston, TX
    Posts
    1,057
    Found out that I can just add the - to the front of the variable and it will work.
    -var1
    michael
    I'm off to GalahTech, hope to see you there.

    If you don't like the rules they make, refuse to play their game. -- Steve Ignorant.

  3. #3
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Way back when I was learning C++, this is what we did. It is a very mystical and complicated procedure:
    Code:
    myInt = myInt * -1
    If you wanted to make sure you weren't changing a negative to a positive, you could call the absolute value function/operator, and then the multiplication.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

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