Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to convert numeric value to word

how to convert numeric value to word

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelptutorial
15 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P prateekfgiet

    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

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #6

    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

    1 Reply Last reply
    0
    • P prateekfgiet

      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

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #7

      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

      1 Reply Last reply
      0
      • P prateekfgiet

        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

        S Offline
        S Offline
        saanj
        wrote on last edited by
        #8

        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...

        P 1 Reply Last reply
        0
        • S saanj

          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...

          P Offline
          P Offline
          prateekfgiet
          wrote on last edited by
          #9

          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

          P S 2 Replies Last reply
          0
          • P prateekfgiet

            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

            P Offline
            P Offline
            prateekfgiet
            wrote on last edited by
            #10

            ok thanks i got solution thanks :rose::rose:

            1 Reply Last reply
            0
            • P prateekfgiet

              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

              S Offline
              S Offline
              saanj
              wrote on last edited by
              #11

              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...

              P 1 Reply Last reply
              0
              • S saanj

                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...

                P Offline
                P Offline
                prateekfgiet
                wrote on last edited by
                #12

                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

                S A 2 Replies Last reply
                0
                • P prateekfgiet

                  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

                  S Offline
                  S Offline
                  saanj
                  wrote on last edited by
                  #13

                  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...

                  P 1 Reply Last reply
                  0
                  • P prateekfgiet

                    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

                    A Offline
                    A Offline
                    Abhijit Jana
                    wrote on last edited by
                    #14

                    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

                    1 Reply Last reply
                    0
                    • S saanj

                      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...

                      P Offline
                      P Offline
                      prateekfgiet
                      wrote on last edited by
                      #15

                      ok thanks a lot for the help

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups