|
Posted by Ivαn Sαnchez Ortega on 08/27/07 22:05
dkirkdrei@yahoo.com wrote:
> I am looking for a way to round a number (which will be displayed as a
> dollar amount) to the nearest nickel. Using the php round function
> only allows you to control the number of decimal places in a number. I
> need to round to the nearest .05. For example: 5.36 would be rounded
> to 5.35, 10.49 would be rounded to 10.50, etc.. Any help would be
> greatly appreciated.
Multiply by 20, then round, then divide by 20. That should do it.
function round_to_nickel($number)
{
return ( round( $number*20 ) /20);
}
--
----------------------------------
IvΓ‘n SΓ‘nchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_eat_s_p_a_m_for_breakfast@hotmail.com
Jabber:ivansanchez@jabber.org ; ivansanchez@kdetalk.net
Navigation:
[Reply to this message]
|