J Jon Skeet [C# MVP] Apr 24, 2004 #2 MAY said: how to convert a negative int (e.g -10) to positive (ie.10). THX. Click to expand... Look at Math.Abs(int)
MAY said: how to convert a negative int (e.g -10) to positive (ie.10). THX. Click to expand... Look at Math.Abs(int)
B Bjorn Abelli Apr 24, 2004 #3 ... how to convert a negative int (e.g -10) to positive (ie.10). Click to expand... There's several ways. Some examples: int x = -10; x = -x; // invert from negative to positive ....or you can use the Math.Abs method, if you want a positive value regardless of whether it was negative or positive before. int y = -10; y = Math.Abs(y); // Bjorn A
... how to convert a negative int (e.g -10) to positive (ie.10). Click to expand... There's several ways. Some examples: int x = -10; x = -x; // invert from negative to positive ....or you can use the Math.Abs method, if you want a positive value regardless of whether it was negative or positive before. int y = -10; y = Math.Abs(y); // Bjorn A
J Jan Roelof de Pijper Apr 24, 2004 #4 ... There's several ways. Some examples: int x = -10; x = -x; // invert from negative to positive ...or you can use the Math.Abs method, if you want a positive value regardless of whether it was negative or positive before. int y = -10; y = Math.Abs(y); // Bjorn A Click to expand... Or if you don't want to use the Math class, if( x < 0 ) x = -x ;
... There's several ways. Some examples: int x = -10; x = -x; // invert from negative to positive ...or you can use the Math.Abs method, if you want a positive value regardless of whether it was negative or positive before. int y = -10; y = Math.Abs(y); // Bjorn A Click to expand... Or if you don't want to use the Math class, if( x < 0 ) x = -x ;