在 Math Round 的 'double' 中使用逗号
Using a comma in a 'double' with Math Round
我想用 ,
和 最后两位小数 来显示我的计算金额。 1000.00
= 1,000.00
。我已经尝试了下面的编码,并且它有效,但是当我在最后舍入它时它删除了我的两位小数。
lblTotalInclVatAmount.Content = "R " + Math.Round((double + double),2).ToString("N0");
听起来很简单。任何建议将不胜感激,谢谢! :)
double d = 1000;
string s = d.ToString("N");
s 现在是 1,000.00
The precision specifier indicates the desired number of digits after the decimal point.
因此您正在寻找 ToString("N2")
。
您可以从以下位置查看更多信息:The Numeric ("N") Format Specifier.
我想用 ,
和 最后两位小数 来显示我的计算金额。 1000.00
= 1,000.00
。我已经尝试了下面的编码,并且它有效,但是当我在最后舍入它时它删除了我的两位小数。
lblTotalInclVatAmount.Content = "R " + Math.Round((double + double),2).ToString("N0");
听起来很简单。任何建议将不胜感激,谢谢! :)
double d = 1000;
string s = d.ToString("N");
s 现在是 1,000.00
The precision specifier indicates the desired number of digits after the decimal point.
因此您正在寻找 ToString("N2")
。
您可以从以下位置查看更多信息:The Numeric ("N") Format Specifier.