我需要一个Textbox
显示价格;12,000,000 OR 1 000 (Price)
像这样的小数:MaskedTextBox
我得到:120,000,00 OR 100 0
如果有人可以提供帮助,我将很高兴..
提前谢谢你
你可以DecimalFormat
这样使用:
Double number = Double.valueOf(text);
DecimalFormat dec = new DecimalFormat("#.00 EUR");
String credits = dec.format(number);
TextView tt = (TextView) findViewById(R.id.creditsView);
tt.setText(credits);
另外,请检查此链接
希望对您有所帮助!
decimal a = 12000000;
Console.WriteLine(a.ToString());
//output=> 12000000
Console.WriteLine(a.ToString("N"));
//output=>12,000,000.00
Console.WriteLine(a.ToString("N1"));
//output=>12,000,000.0
Console.WriteLine(a.ToString("N0"));
//output=>12,000,000
尝试将此代码添加到KeyUp
您的事件处理程序TextBox
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text))
{
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
int valueBefore = Int32.Parse(textBox1.Text, System.Globalization.NumberStyles.AllowThousands);
textBox1.Text = String.Format(culture, "{0:N0}", valueBefore);
textBox1.Select(textBox1.Text.Length, 0);
}
}