Thread: Number-to-Word Algorithm

  1. #1
    Registered User byte's Avatar
    Join Date
    Aug 2005
    Posts
    8

    Question Number-to-Word Algorithm

    Does anybody made a program that will translate a number to it's word equivalent?

    SAMPLE:

    number: 12345
    word: twelve thousand three hundred fourty five
    I can't make an algorithm for it.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    It appears this question has been discussed before
    You can use the board search to find some examples. Here's a couple

    http://cboard.cprogramming.com/showthread.php?t=44180
    http://cboard.cprogramming.com/showthread.php?t=37938

    I'd read the threads for help with an idea, then try to implement your own solution.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I wrote my own . . . fancy, but it used a long, so it couldn't do 10,000,000,000.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    I have a program in Emacs Lisp that does this task. If you can figure out the language (It helps to use the Emacs text editor), you'll see how the algorithm works. Mind, it would return "twelve thousand three hundred forty-five" for 12345, because that's the correct form. And I sort of didn't comment the code at all, either, but it's relatively short. The function 'wordate' is the one that converts the number to text; the rest are helper functions. So the expression (wordate "12345") would return "twelve thousand three hundred forty-five". Hopefully this helps you write the program in your language of choice.

  5. #5
    Registered User byte's Avatar
    Join Date
    Aug 2005
    Posts
    8
    Thanks guys. Really a big help... ;-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  2. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. prime number algorithm
    By Unregistered in forum C++ Programming
    Replies: 12
    Last Post: 02-22-2002, 11:30 PM