Math.Round函數
Math.Round這個函數的解釋是將值按指定的小數位數舍入,但並不就是四捨五入。這種舍入有時稱為就近舍入或四舍六入五成雙
其實在 VB, VBScript, C#, J#, T-SQL 中 Round 函數都是採用 Banker's rounding(銀行家舍入)演算法,即四舍六入五取偶。事實上這也是 IEEE 規定的舍入標準。因此所有符合 IEEE 標準的語言都應該是採用這一演算法的。
如果大家想要四舍五入,記得要加上參數MidpointRounding.AwayFromZero
decimal a_Round = 0;
a_Round = Math.Round(Convert.ToDecimal("5.265"), 2); //結果為5.26 (銀行家舍入算法 MidpointRounding.ToEven參數)
a_Round = Math.Round(Convert.ToDecimal("5.266"), 2); //結果為5.27 (銀行家舍入算法 MidpointRounding.ToEven參數)
a_Round = Math.Round(Convert.ToDecimal("5.275"), 2); //結果為5.28 (銀行家舍入算法 MidpointRounding.ToEven參數)
a_Round = Math.Round(Convert.ToDecimal("5.265"), 2, MidpointRounding.AwayFromZero); //結果為5.27 (四舍五入算法)
a_Round = Math.Round(Convert.ToDecimal("5.265"), 2, MidpointRounding.ToEven); //結果為5.26 (銀行家舍入算法)
a_Round = Math.Round(Convert.ToDecimal("5.275"), 2, MidpointRounding.AwayFromZero); //結果為5.28 (四舍五入算法)
a_Round = Math.Round(Convert.ToDecimal("5.275"), 2, MidpointRounding.ToEven); //結果為5.28 (銀行家舍入算法)
但 MS SQL並不是
MS SQL的Round函數是四舍五入的
Math.Round函數的更多相关文章
- callable函数 stride的意义 Math.round(),Math.ceil(),Math.floor()用法
callable()函数检查一个函数是否可以调用 如果返回True,object仍然可能调用失败:但如果返回False,调用对象ojbect绝对不会成功. 对于函数, 方法, lambda 函式, 类 ...
- Oracle Round 函式 (四捨五入)
Oracle Round 函式 (四捨五入)描述 : 傳回一個數值,該數值是按照指定的小數位元數進行四捨五入運算的結果.SELECT ROUND( number, [ decimal_places ] ...
- 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后,向下取整 ...
- oracle decode(nvl(estimate_qty,0),0,1,estimate_qty) 函數
oracle decode(nvl(estimate_qty,0),0,1,estimate_qty) 函數
- C#中Math.Round()实现中国式四舍五入
C#中Math.Round()实现中国式四舍五入 C#中的Math.Round()并不是使用的"四舍五入"法.其实在VB.VBScript.C#.J#.T-SQL中Round函数都 ...
随机推荐
- EditText 控件
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content&q ...
- allpaths 使用
软件下载与说明:http://www.broadinstitute.org/software/allpaths-lg/blog/?page_id=12 原始数据的深度要达到100以上. 至少要两个库, ...
- less 快捷操作
查找操作: /pattern 向前查找包含pattern的行 ?pattern 向后查找包含pattern的行 n 查找下一个pattern 的行 N 查找上一个pattern的行 ESC-u ...
- xmind第一天笔记
- SlidingMenu实战系列
http://blog.csdn.net/yangyu20121224/article/category/1431917
- UVA 11997 STL 优先队列
题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- leetcode 129. Sum Root to Leaf Numbers ----- java
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
- leetcode 116 Populating Next Right Pointers in Each Node ----- java
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...
- C语言 a和&a的区别
节选自<C语言深度剖析> 首先看个例子 main() { int a[5]={1,2,3,4,5}; int *ptr=(int *)(&a+1); printf("%d ...
- how to change the AlexNet into FCNs ?
How to change the AlexNet into FCNs ? FCNs is a network that only contain convolution layers and no ...