博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#取整函数Math.Round、Math.Ceiling和Math.Floor
阅读量:4691 次
发布时间:2019-06-09

本文共 770 字,大约阅读时间需要 2 分钟。

1.Math.Round:四舍六入五取偶

引用内容
Math.Round(0.0) //0Math.Round(0.1) //0Math.Round(0.2) //0Math.Round(0.3) //0Math.Round(0.4) //0Math.Round(0.5) //0Math.Round(0.6) //1Math.Round(0.7) //1Math.Round(0.8) //1Math.Round(0.9) //1

 

说明:对于1.5,因要返回偶数,所以结果为2。
2.Math.Ceiling:只要有小数都加1

引用内容
Math.Ceiling(0.0) //0Math.Ceiling(0.1) //1Math.Ceiling(0.2) //1Math.Ceiling(0.3) //1Math.Ceiling(0.4) //1Math.Ceiling(0.5) //1Math.Ceiling(0.6) //1Math.Ceiling(0.7) //1Math.Ceiling(0.8) //1Math.Ceiling(0.9) //1

 

说明:例如在分页算法中计算分页数很有用。

3.Math.Floor:总是舍去小数

引用内容
Math.Floor(0.0) //0Math.Floor(0.1) //0Math.Floor(0.2) //0Math.Floor(0.3) //0Math.Floor(0.4) //0Math.Floor(0.5) //0Math.Floor(0.6) //0Math.Floor(0.7) //0Math.Floor(0.8) //0Math.Floor(0.9) //0

 

 

转载于:https://www.cnblogs.com/rwh871212/p/6962099.html

你可能感兴趣的文章
mysql DML DDL DCL
查看>>
RAMPS1.4 3d打印控制板接线与测试1
查看>>
python with语句中的变量有作用域吗?
查看>>
24@Servlet_day03
查看>>
初级ant的学习
查看>>
redis数据结构--String
查看>>
POJ 3279 Fliptile (二进制枚举)
查看>>
memcached 细究(三)
查看>>
future
查看>>
关于main函数传参数的问题
查看>>
getTickCount()函数 VS GetTickCount()函数
查看>>
嵌入式jetty
查看>>
2017~回顾分享
查看>>
使用svn——项目的目录布局
查看>>
RSA System.Security.Cryptography.CryptographicException
查看>>
webservice整合spring cxf
查看>>
[解题报告] 100 - The 3n + 1 problem
查看>>
Entity Framework 学习高级篇1—改善EF代码的方法(上)
查看>>
Mybatis逆向工程配置文件详细介绍(转)
查看>>
String类的深入学习与理解
查看>>