js和c#小数四舍五入

<script language="javascript"> 
document.write("<h1>JS保留两位小数例子</h1><br>");  
   var a=2.1512131231231321;  
   document.write("原来的值:"+a+"<br>");  
   document.write("两位小数点:"+a.toFixed(2)+"<br>四位小数点"+a.toFixed(4));  
</script> 
JS
Math.Round(45.367,2)     //Returns   45.37
Math.Round(45.365,2)     //Returns   45.36

 C#中的Round()不是我们中国人理解的四舍五入,是老外的四舍五入,是符合IEEE标准的四舍五入,具体是四舍六入,下面的才是符合中国人理解的四舍五入

Math.Round(45.367,2,MidpointRounding.AwayFromZero);//45.37

Math.Round(45.365,2,MidpointRounding.AwayFromZero)     //Returns   45.37   
C#
原文地址:https://www.cnblogs.com/tpfOfBlog/p/6282686.html