-2

我需要一个Textbox显示价格;12,000,000 OR 1 000 (Price)
像这样的小数:MaskedTextBox我得到:120,000,00 OR 100 0

如果有人可以提供帮助,我将很高兴..
提前谢谢你

4

3 回答 3

1

你可以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);

另外,请检查此链接

希望对您有所帮助!

于 2013-04-16T05:18:50.500 回答
1
 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
于 2013-04-16T05:18:59.377 回答
1

尝试将此代码添加到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);
    }
}
于 2013-04-16T05:22:02.827 回答