首页 > 其他 > 详细

金额保留两位小数

时间:2020-03-26 09:42:22      阅读:57      评论:0      收藏:0      [点我收藏+]

 

进行四舍五入:

Convert.ToDecimal(1.66666.ToString("f" + decimalCount))

不进行四舍五入:

public static decimal CutDecimalWithN(decimal d, int n)
{
string strDecimal = d.ToString();
int index = strDecimal.IndexOf(".");
if (index == -1 || strDecimal.Length < index + n + 1)
{
strDecimal = string.Format("{0:F" + n + "}", d);
}
else
{
int length = index;
if (n != 0)
{
length = index + n + 1;
}
strDecimal = strDecimal.Substring(0, length);
}
return Decimal.Parse(strDecimal);
}

金额保留两位小数

原文:https://www.cnblogs.com/nayilvyangguang/p/12572052.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!