Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Converting integers to english representation

Reply
Thread Tools

Converting integers to english representation

 
 
Guest
Posts: n/a
 
      08-31-2004
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
 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      08-31-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Martin Maney
Guest
Posts: n/a
 
      09-08-2004
(E-Mail Removed) 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
 
Reply With Quote
 
Cameron Laird
Guest
Posts: n/a
 
      09-09-2004
In article <chnjm7$56d$(E-Mail Removed)14.net>,
Martin Maney <(E-Mail Removed)> wrote:
>(E-Mail Removed) 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.p...ttic/number.py >
and <URL: http://wiki.tcl.tk/591 >.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Representation of integers Shao Miller C Programming 9 01-18-2013 02:25 PM
representation of integers(again) very annoying.. Mantorok Redgormor C Programming 4 10-14-2003 02:33 AM
Bitmask representation of integers =?iso-8859-9?Q?Tongu=E7?= Yumruk Python 3 10-08-2003 02:50 PM
displaying underlying representation of integers Mantorok Redgormor C Programming 5 09-27-2003 01:26 AM
Representation of integers Mantorok Redgormor C Programming 10 09-17-2003 03:41 PM



Advertisments