Programming Challenge Numbers to Text?

Jesse Stay jessestay at gmail.com
Fri May 5 14:15:51 MDT 2006


On 5/2/06, Steve <smorrey at gmail.com> wrote:
> Hello all,
> This is prolly a little offtopic, but I'm wondering if anyone can
> recommend a good quick method of converting numbers to text.
> For instance if I wanted to replace all instances of 100 with the
> words One Hundred, is there something already written, a library
> somewhere?  This seems like something that should have been tackled
> ages ago and is probably a part of some entry level C++ courses, but
> the only way I can think of doing it would be one helaciously long
> switch statement.  Fortunately this would only need to cover the
> numbers 0 to 100.
> It does need to be done in C/C++ though.

Some of Perl's Lingua::EN modules do this.  You may want to either
utilize them (assuming Perl is an option), or look at what good 'ol
Mr. Conway has done to accomplish that.

Jesse

--

#!/usr/bin/perl
$^=q;@!>~|{>krw>yn{u<$$<Sn||n<|}j=<$$<Yn{u<Qjltn{ > 0gFzD gD, 00Fz,
0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/
#y,d,s,(\$.),$1,gee,print


More information about the PLUG mailing list