How to convert a positive number to negative number and negative to positive in C#?


Hello, I would like to know, How can I convert a positive number ( int type) to a negative number in C# and vice-versa ( negative to positive number using C#)?

 

 


Asked by:- bhanu
0
: 74 At:- 6/3/2019 6:00:56 PM
C# positive-to-negative-int negative-to-positive-int






1 Answers
profileImage Answered by:- pika

To Convert positive number to negative number using C#

int myNegInt = System.Math.Abs(myNumber) * (-1);

or Simply

int NegNumber= -System.Math.Abs(myNumber)

To Convert negative number to positive number in C#

var NegativeNumber= -1010;
var PositiveNumber=Math.Abs(NegativeNumber); //output 1010

That's it.

1
At:- 6/6/2019 7:38:48 AM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use