Is there a Java function to convert a positive int to a negative one and a negative int to a positive one?
I'm looking for a reverse
function to perform this conversion:
-5 -> 5 5 -> -5
To convert positive int to negative and vice-versa, use the Bitwise Complement Operator.
Multiply with Minus One to Convert a Positive Number So you can use the same method in excel to convert a negative number into a positive. All you have to do just multiply a negative value with -1 and it will return the positive number instead of the negative.
You can do it with a division too: num /= -1; .
What about x *= -1;
? Do you really want a library function for this?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With