【问题标题】:textbox to display currency显示货币的文本框
【发布时间】:2014-11-13 18:30:42
【问题描述】:

我正在编写我的第一个程序,我正在使用 Visual Studio 2013。我正在从事的项目是针对学校的,是一个工资系统。我们使用的语言是 C#,是一个 Windows 窗体应用程序。到目前为止,我已经获得了非常棒的正确输出,即使不需要,我也想以货币格式显示输出。任何指导或方向将不胜感激。我尝试在堆栈溢出中搜索我的答案,但我觉得很多答案超出了我的理解范围,因为我才这样做了一周

这是我的代码。用户输入员工的工作时间和工资率。输出是总工资、联邦预扣税 (15%) 州预扣税 (5%) 和净工资。

  private void button1_Click(object sender, EventArgs e)
    {
        // add two textboxes together
        Int32 val1 = Convert.ToInt32(textBox1.Text);
        Int32 val2 = Convert.ToInt32(textBox2.Text);
        Int32 val3 = val1 * val2;
        // gross pay result
         textBox3.Text = val3.ToString();
        // federal witholdings
        decimal number = int.Parse(textBox3.Text);
        decimal fW = number * 15 / 100;
        textBox4.Text = fW.ToString();
        // state witholdings
        decimal sW = number * 5 / 100;
        textBox5.Text = sW.ToString();
         //Net pay, defined as gross pay minus taxes
        Int32 val4 = Convert.ToInt32(textBox3.Text);
        Int32 val5 = Convert.ToInt32(textBox4.Text);
        Int32 val6 = Convert.ToInt32(textBox5.Text);
        Int32 val7 = (val4- (val5 + val6));
        textBox6.Text = val7.ToString();

【问题讨论】:

标签: c# textbox


【解决方案1】:

您应该为此使用适当的格式字符串:

string.Format("{0:C}", val7);

看到这个类似的问题:

How can i format decimal property to currency

【讨论】:

    【解决方案2】:
     textBox6.Text = String.Format("{0:C}", val7);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多