Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: adding st,nd,rd and th to numbers

by zshzn (Hermit)
on Jul 19, 2005 at 19:18 UTC ( [id://476239]=note: print w/replies, xml ) Need Help??


in reply to adding st,nd,rd and th to numbers

Is there any reason why you couldn't just use this?
my $num = $ARGV[0]; $num .= 'st' if (substr($num, -1) == 1); $num .= 'nd' if (substr($num, -1) == 2); $num .= 'rd' if (substr($num, -1) == 3); $num .= 'th' if (substr($num, -1) > 3); print "$num\n";

Replies are listed 'Best First'.
Re^2: adding st,nd,rd and th to numbers
by nothingmuch (Priest) on Jul 19, 2005 at 19:29 UTC
    Well, the 11st and 12nd reasons for one.

    Update: the 10 reason is also malfunctioning.

    -nuffin
    zz zZ Z Z #!perl
      Sorry, those few odd numbers obviously passed over my mind. I retract my answer.
Re^2: adding st,nd,rd and th to numbers
by zshzn (Hermit) on Jul 19, 2005 at 19:33 UTC
    If I can slightly add to that, it needs a similar case for 0.

    It doesn't structure as if, elsif, else, because should it work on any case the addition will guarantee that it will not pass on any of the following.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://476239]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-20 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found