我想在我的文本框中放置千位分隔符。我编写了以下代码,但效果不佳。例如 :
1-我不能输入 30000。
2- 123,456 => 561,234。
问题是什么?
private void TextBoxCostTextChanged(object sender, EventArgs e)
{
try
{
var context = this.TextBoxCost.Text;
bool ischar = true;
for (int i = 0; i < context.Length; i++)
{
if (char.IsNumber(context[i]))
{
ischar = false;
break;
}
}
if (ischar)
{
TextBoxCost.Text = null;
}
**TextBoxCost.Text = string.Format("{0:#,###}", double.Parse(TextBoxCost.Text));**
}
catch (Exception ex)
{
ExceptionkeeperBll.LogFileWrite(ex);
}
}