is there some code that I can write so that like if I have -3 it auto maticly turns in into 3?
Printable View
is there some code that I can write so that like if I have -3 it auto maticly turns in into 3?
oh yea, I dont want to remove one character and also, if its a positive, I want to turn it into a negative
Negative to positive:
Positive to negative:Code:Dim Number As Integer
Number = -5
Number = Abs(Number)
Code:Dim Number As Integer
Number = 5
Number = Number - (2 * Number)
try this:
dim i as integer
If i > 0 then
i = i - (i*2)
else
If i < 0 then
i = i + (i*2)
else
end if
end if
thanks, oetje, go here:
http://forums.vb-world.net/showthrea...threadid=28084
Thanks for the credits.:)
newnumber = abs(number) * sgn(number) * -1
Why so much code? :rolleyes:
Change a number from positive to negative and from negative to positive in one simple instruction:
Code:TheNumber = -TheNumber
becuase I have an integer
and I'm not sure if this will work:
intb = -intb
but I got what I needed, I needed it for the link above
That was cool Yonatan.
or you can use Abs
it gives the absolute value of a number.Code:TheNegToPos = Abs(TheNegToPos)
I think thats what I used, read above (oetje's post)
abs would give only change a negative number to a positive number and not the vice versa.
Yonatan's code would be the best if the sign is to be changed for both positive and negative numbers.Otherwise abs is just fine.
do you guys read the first posts? for the backward thing, oetje used another medthod.