note 89655 added to function.number-format
| From: | IMSoP at osu1 dot php dot net | Date: | Wed, 18 Mar 2009 10:36:55 +0000 |
| Subject: | note 89655 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152073@lists.php.net to get a copy of this message | ||
I'm not sure if this is the right place anyway, but "ben at last dot fm"'s
ordinal function can be simplified further by removing the redundant "floor" (the result
of floor is still a float, it's the "%" that's converting to int) and outer
switch.
Note that this version also returns the number with the suffix on the end, not just the suffix.
<?php
function ordinal($num)
{
// Special case "teenth"
if ( ($num / 10) % 10 != 1 )
{
// Handle 1st, 2nd, 3rd
switch( $num % 10 )
{
case 1: return $num . 'st';
case 2: return $num . 'nd';
case 3: return $num . 'rd';
}
}
// Everything else is "nth"
return $num . 'th';
}
?>
----
Server IP: 92.48.74.199
Probable Submitter: 93.97.191.163
----
Manual Page -- http://www.php.net/manual/en/function.number-format.php
Edit -- https://master.php.net/note/edit/89655
Del: integrated -- https://master.php.net/note/delete/89655/integrated
Del: useless -- https://master.php.net/note/delete/89655/useless
Del: bad code -- https://master.php.net/note/delete/89655/bad+code
Del: spam -- https://master.php.net/note/delete/89655/spam
Del: non-english -- https://master.php.net/note/delete/89655/non-english
Del: in docs -- https://master.php.net/note/delete/89655/in+docs
Del: other reasons-- https://master.php.net/note/delete/89655
Reject -- https://master.php.net/note/reject/89655
Search -- https://master.php.net/manage/user-notes.php