kcott has asked for the wisdom of the Perl Monks concerning the following question:

G'day Monks,

I've been hunting around for a module with a function that will take numerical input (e.g. 0, 10, 200, etc.) and return alphabetic output (e.g. zero, ten, two hundred, etc.).

The closest I got was its complement: Lingua::EN::Words2Nums. This does pretty much exactly what I want except in the wrong direction. :-(

Any help appreciated.

Thanks in advance.

-- Ken

Replies are listed 'Best First'.
Re: Seeking a module to convert numbers to words
by BrowserUk (Patriarch) on Aug 20, 2011 at 15:23 UTC

    You missed Lingua::EN::Numbers?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Excellent! Many thanks BrowserUk - exactly what I was after.

      -- Ken

Re: Seeking a module to convert numbers to words
by Perlbotics (Archbishop) on Aug 20, 2011 at 15:25 UTC

    Maybe: Number::Spell provides functionality for spelling out numbers. Currently only integers are supported.

    Update: Avogadro's constant should be the party-opener...

    Do you know that there are more than six vigintillion elementary entities per mol?

    (in response to 921420 below) ... but then, I found that vigintillion is 1063, not 1023! The modules source also sais it's 1021*3. So maybe this one will work? Do you know that a vigintillion has the prime factorisation 263 x 563? Different bases but same exponents - incredible! (see: also)

      Thanks Perlbotics. This has less functionality than Lingua::EN::Numbers but handles larger numbers. Mind you, if I ever saw something like three vigintillion written down, I'd probably need to look it up. :-)

      So I did look it up: vigintillion = 1063

      Not too sure how to work that into casual conversation without getting my face slapped, though.

      Update: The only number I remember from when I studied molarity is twenty-two point four which is obviously substantially smaller then six vigintillion. :-)

      (I remember it from: 1 mole of a gas at stp has a volume of 22.4l)

      Update 2: s{1023}{1063} - curious typo as my source had the correct value.

      -- Ken

        ... or alternatively filter all numbers first in your document, add some if and else rules here and there and create a %hash with this, it depends on what do you need exactly and could be more eficient if you only need to store what you have