note 93747 modified in function.round by danbrown

From: Date: Fri, 25 Sep 2009 17:08:50 +0000
Subject: note 93747 modified in function.round by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161053@lists.php.net to get a copy of this message
This function will let you round to an arbitrary non-zero number. Zero of course causes a division by zero. <?php function roundTo($number, $to){ return round($number/$to, 0)* $to; } echo roundTo(87.23, 20); //80 echo roundTo(-87.23, 20); //-80 echo roundTo(87.23, .25); //87.25 echo roundTo(.23, .25); //.25 ?> --was-- This function will let you round to an arbitrary non-zero number. Zero of course causes a division by zero. function roundTo($number, $to){ return round($number/$to, 0)* $to; } echo roundTo(87.23, 20); //80 echo roundTo(-87.23, 20); //-80 echo roundTo(87.23, .25); //87.25 echo roundTo(.23, .25); //.25 http://php.net/manual/en/function.round.php

« previous php.notes (#161053) next »