【发布时间】:2013-04-16 13:22:02
【问题描述】:
我需要Textbox 来显示价格;小数如:12,000,000 OR 1 000 (Price)
使用MaskedTextBox 我得到:120,000,00 OR 100 0
如果有人能提供帮助,我将不胜感激..
提前谢谢你
【问题讨论】:
-
你的要求不清楚!!!
-
您需要什么帮助?拖放的东西就在那里。
我需要Textbox 来显示价格;小数如:12,000,000 OR 1 000 (Price)
使用MaskedTextBox 我得到:120,000,00 OR 100 0
如果有人能提供帮助,我将不胜感激..
提前谢谢你
【问题讨论】:
尝试将此代码添加到您的TextBox 的KeyUp 事件处理程序
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);
}
}
【讨论】:
你可以像这样使用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);
另外,请查看Link
希望对你有帮助!
【讨论】:
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
【讨论】: