zoukankan      html  css  js  c++  java
  • c# 小数取整

    向上取整
    math.ceiling(1) = 1
    math.ceiling(1.1) = 2
    math.ceiling(1.5) = 2
    向下取整
    math.float(1) = 1
    math.float(1.1) = 1
    math.float(1.5) = 1
    
    C#取整函数实例应用详解
    
    C#取整函数的相关使用是我们在实际开发应用中经常会碰到的具体的实用性概念,那么如何使用好C#取整函数呢?首先我们要明白什么是C#取整函数以及C#取整函数的使用规范。
    C#取整函数使用实例:
    Math.Round是"就近舍入",当要舍入的是5时与"四舍五入"不同(取偶数),如:
    Math.Round(0.5,0)=0    
    Math.Round(1.5,0)=2    
    Math.Round(2.5,0)=2    
    Math.Round(3.5,0)=4    
    ....    
    Math.Ceiling(3.1)=4;    
    Math.Floor(3.9)=3;   
    取天板值与地板值,与"四舍五入"无关。其实Floor的结果与(int)相同,因此也可以这样写Math.Floor((double)2/3+0.5)
    floor 和 ceil是math unit 里的函数,使用前要先 Uses Math。
    trunc 和 round 是system unit 里的函数,缺省就可以用。
    floor 直接往小的取,比如 floor(-123.55)=-124,floor(123.55)=123
    trunc 直接切下整数,比如 trunc(-123.55)=-123, floor(123.55)=123
    ceil 直接往大的取,比如 ceil(-123.55)=-123, ceil(123.55)=124
    round 计算四舍五入,比如 round(-123.55)=-124,round(123.55)=124
    C#取整函数向上取整实例
    int a = 5; int b = 2;   lbl.Text = Convert.ToString(Math.Ceiling((double)a / (double)b)); 
    C#取整函数的相关内容就向你介绍到这里,希望对你了解和学习C#取整函数有所帮助。
  • 相关阅读:
    django-filter 使用Filter来筛选你的数据
    Django REST framework
    利用WSGI来部署你的网站
    [GitPython]使用python管理你的git库
    [模拟炉石](三)使用卡牌
    简单说pyglet.event
    [模拟炉石](二)下一步要解决的问题
    [模拟炉石](一)让游戏过程显示到cocos2d中
    docker系列之一:初见docker
    二分查找_递归实现_存在重复元素
  • 原文地址:https://www.cnblogs.com/smile-wei/p/3316058.html
Copyright © 2011-2022 走看看