note 23502 deleted from function.round by didou

From: Date: Wed, 23 Jul 2003 01:31:41 +0000
Subject: note 23502 deleted from function.round by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-52484@lists.php.net to get a copy of this message
Note Submitter: charly@pache.ch ---- For those who live in countries where the smallest piece of money is 0.05, this function may be helpful to round prices after having added the VAT : function arrondi($nombre) { // on arrondi au centième près : 7.9649 devient 7.66 $nombre=floor(($nombre * 100)+.5)/100; // on sépare la partie entière de la partie flottante : $tab = explode('.',$nombre); // $tab[0] contient 7 // $tab[1] contient 96 $dixieme = substr($tab[1],0,1);// contient 9 $centieme = substr($tab[1],1,1);// contient 6 // on fait le test sur le centieme : if($centieme<=7) { if($centieme<=2) { $retenue = 0; $centieme = 0; } else // on est entre 3 et 7 compris { $retenue = 0; $centieme = 5; } } else // si on est à 8 ou 9 : { $retenue = 1; $centieme = 0; } if($retenue=="1") $dixieme = "0"; // on reconstruit le nombre sans la retenue : $nombre = "".$tab[0].".".$dixieme."".$centieme; // on ajoute la retenue : $nombre += $retenue; return $nombre; } Charly & Sabine

« previous php.notes (#52484) next »