Converting integers to english representation

Discussion in 'Python' started by Guest, Aug 31, 2004.

  1. Guest

    Guest Guest

    Hello All,

    I'm developing a system to parse and enumerate addresses. The
    current obstacle is numbered streets. Does anybody know of a
    module already written to convert integers to their english
    equivalents?

    Example:
    1ST -> FIRST
    SECOND -> 2ND

    or even something like this:
    1 -> ONE
    TWO -> 2

    There's something similar in the dive into python book with
    roman numerals. http://diveintopython.org/unit_testing/index.html

    Anything towards that direction would greatly help and save me
    a lot of time then from starting from scratch.

    Thank you in advance.
    -Brian
    Guest, Aug 31, 2004
    #1
    1. Advertising

  2. Guest

    Peter Hansen Guest

    wrote:

    > I'm developing a system to parse and enumerate addresses. The
    > current obstacle is numbered streets. Does anybody know of a
    > module already written to convert integers to their english
    > equivalents?
    >
    > Example:
    > 1ST -> FIRST
    > SECOND -> 2ND
    >
    > Anything towards that direction would greatly help and save me
    > a lot of time then from starting from scratch.


    The word you are missing is probably 'ordinal', as opposed
    to cardinal (one, two, three) numbers. Google can likely
    help you with a search for "ordinal number convert' or
    such.

    -Peter
    Peter Hansen, Aug 31, 2004
    #2
    1. Advertising

  3. Guest

    Martin Maney Guest

    wrote:
    > I'm developing a system to parse and enumerate addresses. The
    > current obstacle is numbered streets. Does anybody know of a
    > module already written to convert integers to their english
    > equivalents?


    The suggestion about searching for "ordinal" is good, but runs into all
    those unicode false hits. :-(

    It isn't quite the same as either of your examples, and it goes only
    one way, but this is what I'm using in one app where I want ordinalized
    day numbers:

    def _ord_sfx(decade):
    if decade != 1:
    return ('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th')
    return ('th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th')


    def ordinalize(n):
    decade = (n % 100) / 10
    unit = n % 10
    return '%d%s' % (n, _ord_sfx(decade)[unit])

    --
    If nature has made any one thing less susceptible than all others of
    exclusive property, it is the action of the thinking power called an
    idea, which an individual may exclusively possess as long as he keeps
    it to himself; but the moment it is divulged, it forces itself into
    the possession of every one, and the receiver cannot dispossess
    himself of it. -- Thomas Jefferson
    Martin Maney, Sep 8, 2004
    #3
  4. In article <chnjm7$56d$14.net>,
    Martin Maney <> wrote:
    > wrote:
    >> I'm developing a system to parse and enumerate addresses. The
    >> current obstacle is numbered streets. Does anybody know of a
    >> module already written to convert integers to their english
    >> equivalents?

    >
    >The suggestion about searching for "ordinal" is good, but runs into all
    >those unicode false hits. :-(
    >
    >It isn't quite the same as either of your examples, and it goes only
    >one way, but this is what I'm using in one app where I want ordinalized
    >day numbers:
    >
    >def _ord_sfx(decade):
    > if decade != 1:
    > return ('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th')
    > return ('th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th')
    >
    >
    >def ordinalize(n):
    > decade = (n % 100) / 10
    > unit = n % 10
    > return '%d%s' % (n, _ord_sfx(decade)[unit])

    .
    .
    .
    Those who want to pursue this deeper will probably read <URL:
    http://cvs.sourceforge.net/viewcvs.py/snakelets/Snakelets/webapps/test/Attic/number.py >
    and <URL: http://wiki.tcl.tk/591 >.
    Cameron Laird, Sep 9, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UmFlZCBTYXdhbGhh?=

    English/English DLL

    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Oct 15, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,670
    =?Utf-8?B?UmFlZCBTYXdhbGhh?=
    Oct 16, 2005
  2. IchBin
    Replies:
    1
    Views:
    770
  3. Mantorok Redgormor

    Representation of integers

    Mantorok Redgormor, Sep 13, 2003, in forum: C Programming
    Replies:
    10
    Views:
    628
    Kevin D. Quitt
    Sep 17, 2003
  4. Mantorok Redgormor

    displaying underlying representation of integers

    Mantorok Redgormor, Sep 26, 2003, in forum: C Programming
    Replies:
    5
    Views:
    351
  5. Mantorok Redgormor

    representation of integers(again) very annoying..

    Mantorok Redgormor, Oct 13, 2003, in forum: C Programming
    Replies:
    4
    Views:
    457
    Barry Schwarz
    Oct 14, 2003
Loading...

Share This Page