How to Convert Whole Numbers to Currency in C#

Submitted by: 
Language: 
Visitors have accessed this post 76 times.

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

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.