【问题标题】:How does Textbox show price correctly?文本框如何正确显示价格?
【发布时间】:2013-04-16 13:22:02
【问题描述】:

我需要Textbox 来显示价格;小数如:12,000,000 OR 1 000 (Price)
使用MaskedTextBox 我得到:120,000,00 OR 100 0

如果有人能提供帮助,我将不胜感激..
提前谢谢你

【问题讨论】:

  • 你的要求不清楚!!!
  • 您需要什么帮助?拖放的东西就在那里。

标签: c# textbox


【解决方案1】:

尝试将此代码添加到您的TextBoxKeyUp 事件处理程序

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);
    }
}

【讨论】:

    【解决方案2】:

    你可以像这样使用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

    希望对你有帮助!

    【讨论】:

      【解决方案3】:
       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
      

      【讨论】:

        猜你喜欢
        • 2016-02-09
        • 1970-01-01
        • 2022-10-08
        • 1970-01-01
        • 1970-01-01
        • 2021-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多