textbox to display currency

I am writing my first program and I am using Visual Studio 2013. The project I am working on is for school and is a payroll system. The language we are using is C# and is a windows form application. So far I have achieved the correct output which is great, and even though its not required I would like to display the output in a currency format. Any guidance or direction would be appreciated. I've tried to search stack overflow for my answer, but I feel that many of the answers are above my understanding for I have only been doing this for a week

Here is my code. The user inputs the employees hours worked and pay rate. The output is gross pay, federal withholding (15%) state withholding(5%) and net pay.

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

Answers


You should use the apropiate format string for this:

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

See this similar question:

How can i format decimal property to currency


 textBox6.Text = String.Format("{0:C}", val7);

Need Your Help

Regular Expressions in xsl:template match attribute

xml regex xslt xpath

I just want to know if it's possible to use regular expressions in the match attribute of the xsl:template element.

android.os.Build.VERSION_CODES javadoc for details

java android

<?xml version="1.0" encoding="utf-8"?>