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.
Open Microsoft Visual Studio 2015 and create a new windows form application for c#.
Add two labels, two textboxes and a button in the form. After that, design the form just like shown below.
Double click the button and do the following codes to convert the whole number in a currency format when the button is clicked.
- private void button1_Click(object sender, EventArgs e)
- Decimal currency;
- currency = decimal.Parse(textBox1.Text);
- if(currency >= 0)
- textBox2.Text = currency.ToString("##,###.00");
- currency = Math.Abs(currency);
- textBox2.Text = currency.ToString("##,###.00") + "-";
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.