Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Can anybody please tell me logic behind below scenario.

upto 1 crore.
i want alphabet value for numeric value.

e.g. 1234532
twelve lakhs thirty four thousand five hundread and thirty two.

Thanks
Posted
Updated 29-Aug-10 23:07pm
v2
Comments
Toli Cuturicu 30-Aug-10 5:07am    
Reason for my vote of 1
crore? lakhs? Are these actually words?
Anyway, homework type question.
Ankur\m/ 30-Aug-10 5:31am    
Hiren, do you realize what you just wrote violates forum etiquette and is not acceptable. The comments you gave were harsh and MUST not be used.
Crores, lakhs are only used in Indian subcontinent and are not International standards and chances are rare that everyone will know.

I would recommend and request you to visit http://www.codeproject.com/Forums/1580229/General-Indian-Topics.aspx which is there for those Indian audience who are not yet comfortable with the main forums. The purpose of the forum is to allow new Indian members to get a feel for how the site works, be guided by others, and eventually graduate to the main programming and discussion forums. Hope we can help you there achieve the purpose. See you there.
Ankur\m/ 30-Aug-10 5:42am    
I am sorry Toli, I deleted your comment mistakenly. I made it available again but the vote is gone. :(
Hiren solanki 30-Aug-10 5:51am    
ya ankur i admire you but he should have done research before that.
or should not be involved if he doesn't know.
parden for my last words.
and for the person named toli i m telling please see every comment which he has given to other user every comment are relly deserves the word what i have writeen.
Thanks.
Ankur\m/ 30-Aug-10 8:56am    
Well, I just checked his "my vote of 1" comments. It has been reported. But even then, that's not the way you talk to a stranger. There is something called positive attitude. This could have been told to him in a totally different way. Anyways, my point is, think before you speak and be graceful. You are here for help and everyone here is here because he/she loves helping fellow coders. I hope you will consider my suggestions next time.

C#
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{


}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = changeToWords(textBox1.Text, false);
}

public String changeNumericToWords(double numb)
{
String num = numb.ToString();
return changeToWords(num, false);
}
public String changeCurrencyToWords(String numb)
{
return changeToWords(numb, true);
}
public String changeNumericToWords(String numb)
{
return changeToWords(numb, false);
}
public String changeCurrencyToWords(double numb)
{
return changeToWords(numb.ToString(), true);
}
private String changeToWords(String numb, bool isCurrency)
{
String val = "", wholeNo = numb, points = "", andStr = "", pointStr = "";
String endStr = (isCurrency) ? ("Only") : ("");
try
{
int decimalPlace = numb.IndexOf(".");
if (decimalPlace > 0)
{
wholeNo = numb.Substring(0, decimalPlace);
points = numb.Substring(decimalPlace + 1);
if (Convert.ToInt32(points) > 0)
{
andStr = (isCurrency) ? ("and") : ("point");// just to separate whole numbers from points/cents
endStr = (isCurrency) ? ("Cents " + endStr) : ("");
pointStr = translateCents(points);
}
}
val = String.Format("{0} {1}{2} {3}", translateWholeNumber(wholeNo).Trim(), andStr, pointStr, endStr);
}
catch { ;}
return val;
}
private String translateWholeNumber(String number)
{
string word = "";
try
{
bool beginsZero = false;//tests for 0XX
bool isDone = false;//test if already translated
double dblAmt = (Convert.ToDouble(number));
//if ((dblAmt > 0) && number.StartsWith("0"))
if (dblAmt > 0)
{//test for zero or digit zero in a nuemric
beginsZero = number.StartsWith("0");
int numDigits = number.Length;
int pos = 0;//store digit grouping
String place = "";//digit grouping name:hundres,thousand,etc...
switch (numDigits)
{
case 1://ones' range
word = ones(number);
isDone = true;
break;
case 2://tens' range
word = tens(number);
isDone = true;
break;
case 3://hundreds' range
pos = (numDigits % 3) + 1;
place = " Hundred ";
break;
case 4://thousands' range
case 5:
case 6:
pos = (numDigits % 4) + 1;
place = " Thousand ";
break;
case 7://millions' range
case 8:
case 9:
pos = (numDigits % 7) + 1;
place = " Million ";
break;
case 10://Billions's range
pos = (numDigits % 10) + 1;
place = " Billion ";
break;
//add extra case options for anything above Billion...
default:
isDone = true;
break;
}
if (!isDone)
{//if transalation is not done, continue...(Recursion comes in now!!)
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos));
//check for trailing zeros
if (beginsZero) word = " and " + word.Trim();
}
//ignore digit grouping names
if (word.Trim().Equals(place.Trim())) word = "";
}
}
catch { ;}
return word.Trim();
}
private String tens(String digit)
{
int digt = Convert.ToInt32(digit);
String name = null;
switch (digt)
{
case 10:
name = "Ten";
break;
case 11:
name = "Eleven";
break;
case 12:
name = "Twelve";
break;
case 13:
name = "Thirteen";
break;
case 14:
name = "Fourteen";
break;
case 15:
name = "Fifteen";
break;
case 16:
name = "Sixteen";
break;
case 17:
name = "Seventeen";
break;
case 18:
name = "Eighteen";
break;
case 19:
name = "Nineteen";
break;
case 20:
name = "Twenty";
break;
case 30:
name = "Thirty";
break;
case 40:
name = "Fourty";
break;
case 50:
name = "Fifty";
break;
case 60:
name = "Sixty";
break;
case 70:
name = "Seventy";
break;
case 80:
name = "Eighty";
break;
case 90:
name = "Ninety";
break;
default:
if (digt > 0)
{
name = tens(digit.Substring(0, 1) + "0") + " " + ones(digit.Substring(1));
}
break;
}
return name;
}
private String ones(String digit)
{
int digt = Convert.ToInt32(digit);
String name = "";
switch (digt)
{
case 1:
name = "One";
break;
case 2:
name = "Two";
break;
case 3:
name = "Three";
break;
case 4:
name = "Four";
break;
case 5:
name = "Five";
break;
case 6:
name = "Six";
break;
case 7:
name = "Seven";
break;
case 8:
name = "Eight";
break;
case 9:
name = "Nine";
break;
}
return name;
}
private String translateCents(String cents)
{
String cts = "", digit = "", engOne = "";
for (int i = 0; i < cents.Length; i++)
{
digit = cents[i].ToString();
if (digit.Equals("0"))
{
engOne = "Zero";
}
else
{
engOne = ones(digit);
}
cts += " " + engOne;
}
return cts;
}
}
 
Share this answer
 
Comments
Christian Graus 30-Aug-10 3:28am    
Given that this is obviously homework, how does a copy and paste solution help the OP to learn ?
OK, this is a basic homework question, and you can find plenty of examples on the web for how to do it. The most logical way, in my mind, is to turn the number into a string then parse it one bit at a time.
 
Share this answer
 
Comments
Hiren solanki 30-Aug-10 9:56am    
As per you told i made my own code for reaching to my solution.
will publish to code project. as soon as possible.
Thanks
The logic is the same your brain implicitely apply while you're reading such numbers. So make it explicit and tell to your computer, i.e. code your own application to perform the task.
:)
 
Share this answer
 
v2
Comments
Hiren solanki 31-Aug-10 7:29am    
thanks followed your words and made my own solution.
that can map upto 39 trailing zeros.
do you want ?
CPallini 31-Aug-10 16:18pm    
If you believe it is a beautiful piece of code, then submit it as technical tip at CodeProject.
Hiren solanki 31-Aug-10 23:54pm    
it is now submitted as a article on the Code project.
Needs approval.
Look then after.
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900