C# Math.Round
不能直接调用Math.Round方法的,这可和Java的不一样哦
Math.Round这个函数的解释是将值按指定的小数位数舍入,并不就是四舍五入。这种舍入有时称为就近舍入或四舍六入五成双
- C# code
-
Math.Round(0.4) //result:0
-
Math.Round(0.6) //result:1
-
Math.Round(0.5) //result:0
-
Math.Round(1.5) //result:2
-
Math.Round(2.5) //result:2
-
Math.Round(3.5) //result:4
-
Math.Round(5.5) //result:6
-
Math.Round(6.5) //result:6
-
Math.Round(8.5) //result:8
-
Math.Round(9.5) //result:10
可以看出 并不是四舍五入的 其实在 VB, VBScript, C#, J#, T-SQL 中 Round 函数都是采用 Banker's rounding(银行家舍入)算法,即四舍六入五取偶。事实上这也是 IEEE 规定的舍入标准。因此所有符合 IEEE 标准的语言都应该是采用这一算法的。
请调用 Math.Round(Decimal, MidpointRounding) 重载!~哦,原来还有重载的方法可用,MidpointRounding在两个数字之间时如何舍入的规范,规范MidpointRounding中它有2个成员,一个是ToEven还有个是AwayFromZero。
- C# code
-
//四舍五入 Math.Round(0.5,MidpointRounding.AwayFromZero)
C# Math.Round的更多相关文章
- Javascript四舍五入(Math.round()与Math.pow())
代码 Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ ...
- Javascript Math.ceil()与Math.round()与Math.floor()区别
Math.ceil()向上舍入 1 2 3 alert(Math.ceil(20.1)) //输出 21 alert(Math.ceil(20.5)) //输出 21 alert(Math.ceil( ...
- Math.Round四舍五入
Math.Round函数四舍五入的问题 今天客户跑过来跟我说,我们程序里面计算的价格不对,我检查了一下,发现价格是经过折算后的价格,结果是可能小数位较多,而单据上只能打印两位价格,所以就对价格调用 ...
- 【JAVA】Math.Round()函数常见问题“四舍5入”
java.lang.Math.Round()使用时候,处理方式整理,方便以后查找 /** * 测试函数 2014-01-10 */ public class TestMath { pu ...
- js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结
Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整 ...
- C#中Math.Round()实现中国式四舍五入
C#中Math.Round()实现中国式四舍五入 C#中的Math.Round()并不是使用的"四舍五入"法.其实在VB.VBScript.C#.J#.T-SQL中Round函数都 ...
- Math.Round函数详解
有不少人误将Math.Round函数当作四舍五入函数在处理, 结果往往不正确, 实际上Math.Round采用的是国际通行的是 Banker 舍入法. Banker's rounding(银行家舍入) ...
- Math.Round函數
Math.Round這個函數的解釋是將值按指定的小數位數舍入,但並不就是四捨五入.這種舍入有時稱為就近舍入或四舍六入五成雙 其實在 VB, VBScript, C#, J#, T-SQL 中 Roun ...
- .Net中Math.Round与四舍五入
有不少人误将Math.Round函数当作四舍五入函数在处理, 结果往往不正确, 实际上Math.Round采用的是国际通行的是 Banker 舍入法. Banker's rounding(银行家舍入) ...
- C# Math.Round中国式的四舍五入法
double dou = 1.255; //这种是错误的 double dou_result = Math.Round(dou, 2); //结果: 1.25 dou_result = Math.Ro ...
随机推荐
- LeetCode——max-points-on-a-line
Question Given n points on a 2D plane, find the maximum number of points that lie on the same straig ...
- HBase-过滤器(各种过滤器及代码实现)
过滤器简介 HBase过滤器提供了非常强大的特性来帮助用户提高其处理表中数据的效率. HBase中两种主要的数据读取函数是get和scan,它们都支持直接访问数据和通过指定起止行键访问数据的功能.可以 ...
- mapreduce实现学生平均成绩
思路: 首先从文本读入一行数据,按空格对字符串进行切割,切割后包含学生姓名和某一科的成绩,map输出key->学生姓名 value->某一个成绩 然后在reduce里面对成绩进行遍历 ...
- 什么是CDN 域名预热
通常大家理解的预热功能是,缓存预热.将需要预热的资源推送到CDN边缘节点,用户访问时将不需要再回源站,可以直接命中缓存.这样可以加快资源的首次访问,同时缓解突增回源流量给源站造成的压力.这里说的是域名 ...
- Can't connect to MySQL server on 'localhost' (10061)的解决办法!
Can't connect to MySQL server on 'localhost' (10061)的解决办法! http://blog.sina.com.cn/s/blog_52ebca1f01 ...
- div css 练习2
index.html <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-eq ...
- 书_Delphi
1. 有讲 坦克大战 的那本Delphi叫什么 叫做:<<Delphi深度历险>> 2.
- Pycharm如何打断点
一. python代码的调试方式 1. 使用print语句打印出来 2. 在编辑工具中,加断点跟踪(打断点) 3. 使用日志模块,输出到日志中 下面我们来看一下如何打断点 二. 环境 python 3 ...
- 51nod 1163 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163 1163 最高的奖励 基准时间限制:1 秒 空间限制:131072 ...
- c#将DataTable内容导出为CSV文件
写了个类: class DataTableAndCSV { public static DataTable csvToDataTable(string file) { string strConn = ...