zoukankan      html  css  js  c++  java
  • c#中取整和取余

    • "%"为取余。  
    • "/"号整型运算是取整,浮点运算时为除法运算。如54/10结果为5,54.0/10.0结果为5.4。而且取整时不进行四舍五入只取整数部分,如54/10和56/10是5。  
    • Math.Celling()取整数的较大数,相当于不管余数是什么都会进一位。如Math.Celling(54.0/10.0)结果为6。  
    • Math.Floor()取整数的较小数,相当于"/"号,即不管余数部分是什么都不进行进位。如Math.Floor(56.0/10.0)的结果是5。
    using System;
    using System.Collections.Generic;
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("(54/10):{0}", 54 / 10);
                Console.WriteLine("(56/10):{0}", 56 / 10);
                Console.WriteLine("(54.0%10.0):{0}", 54.0 % 10.0);
                Console.WriteLine("(56.0%10.0):{0}", 56.0 % 10.0);
                Console.WriteLine("Math.Celling(54.0/10.0):{0}", Math.Ceiling(54.0 / 10.0));
                Console.WriteLine("Math.Celling(56.0/10.0):{0}", Math.Ceiling(56.0 / 10.0));
                Console.WriteLine("Math.Floor(54.0/10.0):{0}", Math.Floor(54.0 / 10.0));
                Console.WriteLine("Math.Floor(56.0/10.0):{0}", Math.Floor(56.0 / 10.0));
                Console.ReadKey();
            }
        }
    }
    
    (54/10):5
    (56/10):5
    (54.0%10.0):4
    (56.0%10.0):6
    Math.Celling(54.0/10.0):6
    Math.Celling(56.0/10.0):6
    Math.Floor(54.0/10.0):5
    Math.Floor(56.0/10.0):5
  • 相关阅读:
    Go语言基础之切片
    Go语言基础之map
    Go语言基础之函数
    Go语言基础之指针
    Go语言基础之结构体
    Redis缓存失效策略
    redis 的过期策略都有哪些?内存淘汰机制都有哪些?
    关于redis的主从、哨兵、集群
    Redis的 RDB和 AOF持久化的区别
    为什么做分布式使用 Redis
  • 原文地址:https://www.cnblogs.com/chrisghb8812/p/9427203.html
Copyright © 2011-2022 走看看