繁体   English   中英

计算器-C#中的逗号分隔符

[英]Calculator - thousand separator by comma in c#

private void TextBox_TextChanged(object sender, EventArgs e)
{
string value = TextBox.Text.Replace(",", "");
double dbl;
if (double.TryParse(value, out dbl))
{
    TextBox.TextChanged -= TextBoxTextChanged;
    TextBox.Text = string.Format("{0:#,#0}", dbl);
    TextBox.SelectionStart = TextBox.Text.Length;
    TextBox.TextChanged += TextBoxTextChanged;
}

}

我使用上面的代码制作计算器。 我想用十进制值获取结果逗号。 我想在中输入1,234.1234

textBox,但是我无法在Text Box中键入1,234.1234。 我的意思是逗号没有十进制值。

有人可以帮我解决这个问题吗?

您必须提供一种使用的文化。 成千上万的迹象。 通常,您想使用用户当前的文化。

double.TryParse(value, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.CurrentCulture, out dbl)

尝试这个:

int value = 300000
String.Format("{0:#,###0}", value);
// will return 300,000

http://msdn.microsoft.com/zh-CN/library/system.string.format.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM