我知道这个问题之前已经回答过很多次了,但是我确信我的代码是正确的,但不能正常工作。
string total = ds.Tables[0].Rows[0][0].ToString();
string test = string.Format("{0:N}", total);
lbl_totalValue.Text = test;
这段代码并没有像它希望的那样将逗号添加到我的值中。
谁能看出原因?
最佳答案
当你放
string total = ds.Tables[0].Rows[0][0].ToString();
表示隐含的G
("General")格式字符串
string total = ds.Tables[0].Rows[0][0].ToString("G");
不要过早地格式化:
var total = ds.Tables[0].Rows[0][0]; // Value from table
string test = string.Format("{0:N}", total); // Format total with "N" format string
关于c# - 格式化数字字符串以添加逗号 - C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48385226/