View Full Version : Positive to Negative, Negative to Positive
Does anyone know of a slick way to convert positive numbers to negative numbers, and negative numbers to positive ones?
I can check the input string to see if the negative sign – is the first digit, and make my change that way, I know. With my limited knowledge of math, I was wondering if I might be overlooking the obvious.
Thanks.
.
Corey
07-20-2005, 12:15 AM
Multiply by negative one. :yes
Thank you Corey. At least I was smart enough to ask, before I wrote a tight 12 lines of code that was almost able to do the same thing. :)
When the answer to a vexing problem is that easy, I think it’s time to pull out the ol’skateboard, and leave the computer behind for a couple of hours. Thanks again. ;)
.
Intrigued
07-20-2005, 12:50 AM
Ah, ha! That's a good idea I had not thought of myself.
:yes
Corey
07-20-2005, 01:15 AM
I think it’s time to pull out the ol’skateboard, and leave the computer behind for a couple of hours.
*That's* the quote of the year. I just figured it out and so far this year I've averaged about 6 miles per day on my board. Yeee-eee-eeah! :yes
A positive number multiplied by a positive number is always a positive number
A positive number multiplied by a negative number is always a negative number
A negative number multiplied by a negative number is always a positive number
Oh yea, it’s coming back to me now. It looks like Corey paid attention in 5th grade math class. Although in Canada, that’s probably 3rd grade stuff.
6 miles a day, that’s a great average. :yes As soon as I replace my steel wheels with some of those new-fangled polyurethane ones with the enclosed bearings, I might be able to up my average by a couple of feet too.
.
Corey
07-20-2005, 02:02 AM
I owe my life to polyurethane wheels. Literally. :)
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.