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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. String equivalent of a double

String equivalent of a double

Scheduled Pinned Locked Moved C#
tutorial
5 Posts 4 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.
  • E Offline
    E Offline
    edel_ong
    wrote on last edited by
    #1

    Hi, I would like to know how to convert a double to string. Example: double = 3,456,789.30 string equivalent = three million four hundred fifty-six thousand and seven hundred eighty-nine & 30/100 Thanks a lot! I really need this. :)

    O S L 3 Replies Last reply
    0
    • E edel_ong

      Hi, I would like to know how to convert a double to string. Example: double = 3,456,789.30 string equivalent = three million four hundred fifty-six thousand and seven hundred eighty-nine & 30/100 Thanks a lot! I really need this. :)

      O Offline
      O Offline
      originSH
      wrote on last edited by
      #2

      Theres no built in soltuion for this in C# or the .Net Framework, but google[^] has lots of results.

      1 Reply Last reply
      0
      • E edel_ong

        Hi, I would like to know how to convert a double to string. Example: double = 3,456,789.30 string equivalent = three million four hundred fifty-six thousand and seven hundred eighty-nine & 30/100 Thanks a lot! I really need this. :)

        S Offline
        S Offline
        Skippums
        wrote on last edited by
        #3

        digitNames = new string[] { "", "one", "two" ... };
        tensDigitNames = new string[] { "", "ten-", "twenty-", "thirty-" ... };
        magnitudeNames = new string[] { "", " thousand", " million" ... };

        1. Initialize a string called "result" to the fractional part preceded with an "&"
        2. Initialize an integer array called "number" of the digits of the number, from LSD to MSD
          (in your example, {9, 8, 7, ... 3})
        3. Iterate through the digits in "number" to get the variables "curDigit" and "curDigitIdx"
        4. Perform the following logic using curDigitIdx (the index in your array) and curDigit
          switch (curDigitIdx % 3) {
          case 0:
          result = string.Format("{0}{1} {2}", digitNames[curDigit],
          magnitudeNames[curDigitIdx / 3], result);
          break;
          case 1:
          result = string.Format("{0}{1}", tensDigitNames[curDigit], result);
          break;
          case 2:
          result = string.Format("{0} hundred {1}", digitNames[curDigit], result);
          break;
          }

        Note that the preceding code is simply a starting point, and that the formatting will require a number of special cases (such as getting 11 to be printed as "eleven" as opposed to "ten-one" and 50 being printed as "fifty" instead of "fifty-". Hope this helps,

        Sounds like somebody's got a case of the Mondays -Jeff

        1 Reply Last reply
        0
        • E edel_ong

          Hi, I would like to know how to convert a double to string. Example: double = 3,456,789.30 string equivalent = three million four hundred fifty-six thousand and seven hundred eighty-nine & 30/100 Thanks a lot! I really need this. :)

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, CP holds a couple of articles[^] on the subject. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Happy 2008!


          E 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, CP holds a couple of articles[^] on the subject. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Happy 2008!


            E Offline
            E Offline
            edel_ong
            wrote on last edited by
            #5

            Thanks a lot!!!

            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