Decimal类型的值处理为财务的四舍五入,保留2位小数,不足补0的处理

//Decimal类型的值处理为财务的四舍五入,保留2位小数,不足补0的处理
public static string op_moneyx(this Decimal x)
{
	  string str = string.Concat((object) Math.Round(x, 2, MidpointRounding.AwayFromZero));
	  if (!str.Contains("."))
		return str + ".00";
	  if (str.Split('.')[1].Length != 2)
		str += "0";
	  return str;
}

  

记录一下该代码片段方便后续Copy.

posted @ 2023-01-04 11:02  liskov_design  阅读(351)  评论(0)    收藏  举报