通常我们使用Math.Round()函数,是直接调用的,如:

Math.Round(45.367,2)    //返回: 45.37
Math.Round(45.365,2)    //返回: 45.36

上面不是我们理解的四舍五入,是四舍六入,需要改成这样,如:

Math.Round(Convert.ToDecimal(45.367),2,MidpointRounding.AwayFromZero);     //返回: 45.37
 
Math.Round(Convert.ToDecimal(45.365),2,MidpointRounding.AwayFromZero);     //返回: 45.37  

PS: 上面需要我们先把值进行转换成decimal类型,防止精度丢失(接收的变量是float或double会出现这个问题)

参考:

https://www.cnblogs.com/xuliangxing/p/6585865.html

相关文章:

  • 2021-11-22
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-31
  • 2021-06-20
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
相关资源
相似解决方案