四舍五入

Posted xixixing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了四舍五入相关的知识,希望对你有一定的参考价值。

通过double转int只保留整数的特性,实现四舍五入。

        public static void Main(string[] args)
        {
            double number=Convert.ToDouble(Console.ReadLine());
            int res=(int)(number+0.5f);//double转int,只保留整数.
            Console.WriteLine(res);
            Console.ReadKey();
        }

 

以上是关于四舍五入的主要内容,如果未能解决你的问题,请参考以下文章