how to convert numeric value to word
-
ya i have tried a code but when code runs it will give error code is : string Number; string deciml; string _number; string _deciml; string[] US = new string[1003]; string[] SNu = new string[20]; string[] SNt = new string[10]; protected void Page_Load(object sender, EventArgs e) { Initialize(); } public string NameOfNumber(string Number) { string GroupName = ""; string OutPut = ""; if ((Number.Length % 3) != 0) { Number = Number.PadLeft((Number.Length + (3 - (Number.Length % 3))), '0'); } string[] Array = new string[Number.Length / 3]; Int16 Element = -1; Int32 DisplayCount = -1; bool LimitGroupsShowAll = false; int LimitGroups = 0; bool GroupToWords = true; for (Int16 Count = 0; Count <= Number.Length - 3; Count += 3) { Element += 1; Array[Element] = Number.Substring(Count, 3); } if (LimitGroups == 0) { LimitGroupsShowAll = true; } for (Int16 Count = 0; (Count <= ((Number.Length / 3) - 1)); Count++) { DisplayCount++; if (((DisplayCount < LimitGroups) || LimitGroupsShowAll)) { if (Array[Count] == "000") continue; { GroupName = US[((Number.Length / 3) - 1) - Count + 1]; } if ((GroupToWords == true)) { OutPut += Group(Array[Count]).TrimEnd(' ') + " " + GroupName + " "; } else { OutPut += Array[Count].TrimStart('0') + " " + GroupName; } } } Array = null; return OutPut; } private string Group(string Argument) { string Hyphen = ""; string OutPut = ""; Int16 d1 = Convert.ToInt16(Argument.Substring(0, 1)); Int16 d2 = Convert.ToInt16(Argument.Substring(1, 1)); Int16 d3 = Convert.ToInt16(Argument.Substring(2, 1)); if ((d1 >= 1)) { OutPut += SNu[d1] + " hundred "; } if ((double.Parse(Argument.Substring(1, 2)) < 20)) { OutPut += SNu[Convert.ToInt16(Argument.Substring(1, 2))]; } if ((double.Parse(Argument.Substring(1, 2)) >= 20)) { if (Conve
Wow - what a world of ugliness. Have you stopped to read the error message, and consider what it might mean ? Have you stepped through the code ? If you're taking a class, you need to talk to your teacher, you are lost. If you're teaching yourself, buy a book on C# and read it carefully.
Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
-
ya i have tried a code but when code runs it will give error code is : string Number; string deciml; string _number; string _deciml; string[] US = new string[1003]; string[] SNu = new string[20]; string[] SNt = new string[10]; protected void Page_Load(object sender, EventArgs e) { Initialize(); } public string NameOfNumber(string Number) { string GroupName = ""; string OutPut = ""; if ((Number.Length % 3) != 0) { Number = Number.PadLeft((Number.Length + (3 - (Number.Length % 3))), '0'); } string[] Array = new string[Number.Length / 3]; Int16 Element = -1; Int32 DisplayCount = -1; bool LimitGroupsShowAll = false; int LimitGroups = 0; bool GroupToWords = true; for (Int16 Count = 0; Count <= Number.Length - 3; Count += 3) { Element += 1; Array[Element] = Number.Substring(Count, 3); } if (LimitGroups == 0) { LimitGroupsShowAll = true; } for (Int16 Count = 0; (Count <= ((Number.Length / 3) - 1)); Count++) { DisplayCount++; if (((DisplayCount < LimitGroups) || LimitGroupsShowAll)) { if (Array[Count] == "000") continue; { GroupName = US[((Number.Length / 3) - 1) - Count + 1]; } if ((GroupToWords == true)) { OutPut += Group(Array[Count]).TrimEnd(' ') + " " + GroupName + " "; } else { OutPut += Array[Count].TrimStart('0') + " " + GroupName; } } } Array = null; return OutPut; } private string Group(string Argument) { string Hyphen = ""; string OutPut = ""; Int16 d1 = Convert.ToInt16(Argument.Substring(0, 1)); Int16 d2 = Convert.ToInt16(Argument.Substring(1, 1)); Int16 d3 = Convert.ToInt16(Argument.Substring(2, 1)); if ((d1 >= 1)) { OutPut += SNu[d1] + " hundred "; } if ((double.Parse(Argument.Substring(1, 2)) < 20)) { OutPut += SNu[Convert.ToInt16(Argument.Substring(1, 2))]; } if ((double.Parse(Argument.Substring(1, 2)) >= 20)) { if (Conve
prateekfgiet wrote:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
Error clearly says that the value of array is going to outside the boundary. So, Put a breakpoint over there and check the array index.
cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net
-
ya i have tried a code but when code runs it will give error code is : string Number; string deciml; string _number; string _deciml; string[] US = new string[1003]; string[] SNu = new string[20]; string[] SNt = new string[10]; protected void Page_Load(object sender, EventArgs e) { Initialize(); } public string NameOfNumber(string Number) { string GroupName = ""; string OutPut = ""; if ((Number.Length % 3) != 0) { Number = Number.PadLeft((Number.Length + (3 - (Number.Length % 3))), '0'); } string[] Array = new string[Number.Length / 3]; Int16 Element = -1; Int32 DisplayCount = -1; bool LimitGroupsShowAll = false; int LimitGroups = 0; bool GroupToWords = true; for (Int16 Count = 0; Count <= Number.Length - 3; Count += 3) { Element += 1; Array[Element] = Number.Substring(Count, 3); } if (LimitGroups == 0) { LimitGroupsShowAll = true; } for (Int16 Count = 0; (Count <= ((Number.Length / 3) - 1)); Count++) { DisplayCount++; if (((DisplayCount < LimitGroups) || LimitGroupsShowAll)) { if (Array[Count] == "000") continue; { GroupName = US[((Number.Length / 3) - 1) - Count + 1]; } if ((GroupToWords == true)) { OutPut += Group(Array[Count]).TrimEnd(' ') + " " + GroupName + " "; } else { OutPut += Array[Count].TrimStart('0') + " " + GroupName; } } } Array = null; return OutPut; } private string Group(string Argument) { string Hyphen = ""; string OutPut = ""; Int16 d1 = Convert.ToInt16(Argument.Substring(0, 1)); Int16 d2 = Convert.ToInt16(Argument.Substring(1, 1)); Int16 d3 = Convert.ToInt16(Argument.Substring(2, 1)); if ((d1 >= 1)) { OutPut += SNu[d1] + " hundred "; } if ((double.Parse(Argument.Substring(1, 2)) < 20)) { OutPut += SNu[Convert.ToInt16(Argument.Substring(1, 2))]; } if ((double.Parse(Argument.Substring(1, 2)) >= 20)) { if (Conve
-
You are trying to access an item index which does not exist in the array. As Abhijeet rightly said, putting breakpoints and debugging it can track the issue and take you to the resolution. Regards Saanj
Either you love IT or leave IT...
i have put break point, when control reach if ((no[0] != null) && (no[1] != "00")) it gives error how can i remove this error pls tell me i m totally exhaust. pls help me
-
i have put break point, when control reach if ((no[0] != null) && (no[1] != "00")) it gives error how can i remove this error pls tell me i m totally exhaust. pls help me
ok thanks i got solution thanks :rose::rose:
-
i have put break point, when control reach if ((no[0] != null) && (no[1] != "00")) it gives error how can i remove this error pls tell me i m totally exhaust. pls help me
-
May be no[1] != "00" is giving error because you are not checking for the null value. Regards Saanj
Either you love IT or leave IT...
yea due to null value its give error. thanks one more problem is here when i put 223456.00, it converts in to Rupees Two hundred Twenty Three Thousand Four hundred Fifty Six Only while it should be rupees two lac twenty three thousand four hundred fifty six only pls help me about this
-
yea due to null value its give error. thanks one more problem is here when i put 223456.00, it converts in to Rupees Two hundred Twenty Three Thousand Four hundred Fifty Six Only while it should be rupees two lac twenty three thousand four hundred fifty six only pls help me about this
Hi, It's tough to answer this question as debugging is the only way. So, I think you are missing some checks (I mean some condition is getting failed) which cause a wrong sentence. This is my guess which came from my previous experience. I also had a similar kind of problem like yours. But one thing only I can remember is the condition checking. So try to debug and check all consitions in your code. All the best. Regards Saanj
Either you love IT or leave IT...
-
yea due to null value its give error. thanks one more problem is here when i put 223456.00, it converts in to Rupees Two hundred Twenty Three Thousand Four hundred Fifty Six Only while it should be rupees two lac twenty three thousand four hundred fifty six only pls help me about this
prateekfgiet wrote:
when i put 223456.00, it converts in to Rupees Two hundred Twenty Three Thousand Four hundred Fifty Six Only while it should be rupees two lac twenty three thousand four hundred fifty six only
Debugging is the only one way to resolve your problem. Check the condition properly.
cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net
-
Hi, It's tough to answer this question as debugging is the only way. So, I think you are missing some checks (I mean some condition is getting failed) which cause a wrong sentence. This is my guess which came from my previous experience. I also had a similar kind of problem like yours. But one thing only I can remember is the condition checking. So try to debug and check all consitions in your code. All the best. Regards Saanj
Either you love IT or leave IT...
ok thanks a lot for the help