[Reserved] C # Math.Round method using calculation results of round-off operation

In the numerical calculation of C #, sometimes we need to round-off operation results of the calculation, at this time can use the built-in methods to achieve method Math.Round rounding operation, a plurality of overloaded functions Math.Round method, the median of the effective support provided rounded, if there is no set number of significant digits, the default rounded to the corresponding number of significant digits.

Math.Round overloads several commonly used methods are:

(1) data type for rounding a decimal decimal, integer bit reserved directly decimal Round (decimal d);

(2) for the type of data type double double rounded directly after the decimal bit (1) for the data type of decimal rounding decimal, integer bit reserved direct double Round (double a);

(3) for decimal decimal data type, the number of decimal places specified retention decimal Round (decimal d, int decimals);

(4) type for double precision data type double rounding, decimal places designated reserved Round double (double value, int digits);

For example as follows:

   NUM = 3.446D Double;
   Double RESULT1 = Math.Round (NUM); // get a result. 3
   Double result2 = Math.Round (NUM, 2); // result is obtained 3.45

  num1 = 3.446M decimal;
 decimal result3 = Math.Round (num1); // get a result. 3
  decimal result4 = Math.Round (num1, 2); // result is obtained 3.45

Note: The text reproduced from personal bloggers station IT technology small fun house , the original link C # using the method of calculation results Math.Round rounding operation _IT technology small fun house .

Guess you like

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