Hi,
In my window form application, there is need to convert total amount ( which is in digit) into text. Is there any function for converting digit into text? Plz,help.
Thanks, in advance.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 12, 2011, 7:13 PM EST
Try this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Number_to_word_in_csharp
{
public partial class Form1 : Form
{
int n = 0;
string x = null;
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
string[] a = {
"One",
"Two",
"Three",
"four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
"Eleven",
"Twelve",
"Thirteen",
"fourteen",
"Fifteen",
"Sixteen",
"Seventeen",
"Eighteen",
"Ninteen"
};
string[] b = {
"Twenty",
"Thirty",
"Fourty",
"Fifty",
"sixty",
"Seventy",
"eighty",
"ninty"
};
x = "";
n = int.Parse(textBox1.Text);
if ((n <= 9999))
{
if ((n > 999 & n <= 9999))
{
x += a[(n / 1000) - 1] + "Thousand";
n = n % 1000;
}
x += " ";
if ((n > 99 & n <= 999))
{
x += a[(n / 100) - 1] + "Hundred";
n = n % 100;
}
x += " ";
if ((n > 19 & n <= 99))
{
x += b[(n / 10) - 2];
n = n % 10;
}
x += " ";
if ((n > 0 & n <= 19))
{
x += a[n - 1];
}
textBox2.Text = x;
}
else
{
textBox2.Text = ("Number is out of range");
}
}
}
}
Thanks
VulpesRank #55 · 29.2K reputationPosted Dec 12, 2011, 11:40 PM EST
http://www.c-sharpcorner.com/uploadfile/b942f9/converting-numbers-to-words-in-C-Sharp/