C#四舍五入操作两种简单方法

class Program
    {
       
staticvoid Main(string[] args)
{
           
double d =5.55;

           
// 方法一
            Console.WriteLine(d.ToString("0.0")); // 5.6
            Console.WriteLine(d.ToString("0"));   // 6

           
// 方法二
            Console.WriteLine(Math.Round(d, 1, MidpointRounding.AwayFromZero)); // 5.6
            Console.WriteLine(Math.Round(d, 0, MidpointRounding.AwayFromZero)); // 6

            Console.ReadKey();
        }
    }

原文地址:https://www.cnblogs.com/dodui/p/1905098.html