[英]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;
}
} }
I used above code for making Calculator. 我使用上面的代码制作计算器。 I want to get results comma with decimal value.
我想用十进制值获取结果逗号。 I want to type 1,234.1234 in the
我想在中输入1,234.1234
textBox, but I can not type 1,234.1234 in the Text Box. textBox,但是我无法在Text Box中键入1,234.1234。 I mean comma with decimal value not getting.
我的意思是逗号没有十进制值。
Can anybody kindly please help me to solve this problem ? 有人可以帮我解决这个问题吗?
You have to provide a Culture that uses . 您必须提供一种使用的文化。 as thousands sign.
成千上万的迹象。 Normally you want to use the users current culture.
通常,您想使用用户当前的文化。
double.TryParse(value, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.CurrentCulture, out dbl)
Try this: 尝试这个:
int value = 300000
String.Format("{0:#,###0}", value);
// will return 300,000
http://msdn.microsoft.com/en-us/library/system.string.format.aspx http://msdn.microsoft.com/zh-CN/library/system.string.format.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.