Reproduced using C # [] returns the absolute value of a Math.Abs

In the numerical calculation of C #, sometimes we need to calculate the absolute value of the value type of the object, at this time need to use C # class numerical Math class Abs absolute value function, the Math.Abs ​​a total of seven absolute value function overloading types, supports decimal, double, float, int, long, sbyte, short and other types of data objects. The method of calculating an absolute value Math.Ab call format, value representatives Math.Abs ​​(value) of the absolute value of the variable to be calculated.

(1) calculates the absolute value of type decimal decimal type

 decimal, whether = 12.33;
 Surely = Math.abs (whether);

(2) calculation of the absolute value variable type shaping Int

int num = -4;

num = Math.Abs ​​(num); // result is obtained 4

Note: The text reproduced from personal bloggers station technology IT technology small fun house , the original link C # using Math.Abs Returns the absolute value of the interest _IT small house technology .

Guess you like

Origin www.cnblogs.com/xu-yi/p/10993575.html