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函數的更多相关文章

  1. callable函数 stride的意义 Math.round(),Math.ceil(),Math.floor()用法

    callable()函数检查一个函数是否可以调用 如果返回True,object仍然可能调用失败:但如果返回False,调用对象ojbect绝对不会成功. 对于函数, 方法, lambda 函式, 类 ...

  2. Oracle Round 函式 (四捨五入)

    Oracle Round 函式 (四捨五入)描述 : 傳回一個數值,該數值是按照指定的小數位元數進行四捨五入運算的結果.SELECT ROUND( number, [ decimal_places ] ...

  3. Javascript四舍五入(Math.round()与Math.pow())

    代码 Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ ...

  4. 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( ...

  5. Math.Round四舍五入

    Math.Round函数四舍五入的问题   今天客户跑过来跟我说,我们程序里面计算的价格不对,我检查了一下,发现价格是经过折算后的价格,结果是可能小数位较多,而单据上只能打印两位价格,所以就对价格调用 ...

  6. 【JAVA】Math.Round()函数常见问题“四舍5入”

    java.lang.Math.Round()使用时候,处理方式整理,方便以后查找   /**  * 测试函数 2014-01-10  */ public class TestMath {     pu ...

  7. js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结

    Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整 ...

  8. oracle decode(nvl(estimate_qty,0),0,1,estimate_qty) 函數

    oracle   decode(nvl(estimate_qty,0),0,1,estimate_qty) 函數

  9. C#中Math.Round()实现中国式四舍五入

    C#中Math.Round()实现中国式四舍五入 C#中的Math.Round()并不是使用的"四舍五入"法.其实在VB.VBScript.C#.J#.T-SQL中Round函数都 ...

随机推荐

  1. Howto add permanent static routes in Ubuntu

    Static routing is the term used to refer to the manual method used to set up routing. An administrat ...

  2. spark streaming 实现接收网络传输数据进行WordCount功能

    package iie.udps.example.operator.spark; import scala.Tuple2; import org.apache.spark.SparkConf; imp ...

  3. CentOS7.0关于libguestfs的bug

    libguestfs,libguestfs-tools是用来在不启动虚拟机的情况下,快速简单访问虚拟机磁盘的工具. 今天在CentOS7.0系统上通过guestmount命令去mount虚拟机磁盘的时 ...

  4. emulator: ERROR: Unable to load VM from snapshot. The snapshot has been saved for a different hardware configuration.

    emulator: ERROR: Unable to load VM from snapshot. The snapshot has been saved for a different hardwa ...

  5. Codeforces Round #134 (Div. 2)

    A. Mountain Scenery 枚举山顶位置,满足\(r_{i-1} \lt r_i - 1 \gt r_{i+1}\). 范围要开\(2N\). B. Airport 优先队列维护最值. C ...

  6. timus 1136 Parliament(e)

    Parliament Time limit: 1.0 secondMemory limit: 64 MB A new parliament is elected in the state of MMM ...

  7. linux中的find命令——查找文件名

    1.在某目录下查找名为“elm.cc”的文件 find /home/lijiajia/ -name elm.cc 2.查找文件名中包含某字符(如"elm")的文件 find /ho ...

  8. PCA和Softmax分类比较—Mnist与人脸数据集

    PCA人脸识别中三种方法得到的正确率可达到100% 作为对比,单独使用Softmax回归对人脸40*10*92*112的数据分类正确率为97%. 用PCA对MNIST手写数字10*500*28*28识 ...

  9. EasyUI之DataGrid使用

    http://blog.csdn.net/liovey/article/details/9173931 背景介绍: 原 先项目采用普通的jsp页面来做为前端显示,用户体验差,并且为了实现某一种效果需要 ...

  10. 用视频编辑软件打不开jpg格式的图片的解决方法

    有时候我们把PSD.JPG等图片导入到素材库中会发现EDIUS视频编辑软件根本就不支持,显示黑屏状态.可是当我们把图片导入EDIUS NX支持下的premierepro里却能够正常显示.这是什么原因呢 ...