C#向上取整的三种方式

Math.Round():四舍六入五取偶
Math.Floor():向下取整
Math.Ceiling():向上取整

double nn = 20.2;
            double mm = 20.50;
            double mm1 = 21.50;
            double bb = 20.71;
            var num_floor1=Math.Floor(bb);
            var num_floor2 = Math.Floor(mm);
            var num_floor3 = Math.Floor(nn);
            var num_ceiling1 = Math.Ceiling(nn);
            var num_ceiling2 = Math.Ceiling(mm);
            var num_ceiling3 = Math.Ceiling(bb);
            var num_round1 = Math.Round(nn);
            var num_round2 = Math.Round(mm);
            var num_round2_1 = Math.Round(mm1);
            var num_round3 = Math.Round(bb);
            Console.WriteLine("num_floor1_向下取整20.71::::"+num_floor1);
            Console.WriteLine("num_floor2_向下取整20.50::::" + num_floor2);
            Console.WriteLine("num_floor3_向下取整20.2::::" + num_floor3);
         

你可能感兴趣的:(ASP.NET,C#)