How to Convert Whole Numbers to Currency in C#

If you find hard to convert whole numbers to currency, this tutorial is right for you. So, in this tutorial, I will teach you how to convert whole numbers to currency in c#. This method has the ability to convert any whole numbers given in a textbox and it will automatically display to another textbox in a currency format in just a click. Let's begin.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application for c#. ps1

Step 2

Add two labels, two textboxes and a button in the form. After that, design the form just like shown below. figure 2

Step 3

Double click the button and do the following codes to convert the whole number in a currency format when the button is clicked.
  1.  
  2. private void button1_Click(object sender, EventArgs e)
  3. {
  4.  
  5. Decimal currency;
  6.  
  7. currency = decimal.Parse(textBox1.Text);
  8.  
  9. if(currency >= 0)
  10. {
  11. textBox2.Text = currency.ToString("##,###.00");
  12. }
  13. else
  14. {
  15. currency = Math.Abs(currency);
  16. textBox2.Text = currency.ToString("##,###.00") + "-";
  17. }
  18. }

Output

figure 3 The complete source code is included. You can download it and run it on your computer. For any questions about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT Or feel free to comment below.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.