note 70067 deleted from function.number-format by bobby

From: Date: Mon, 02 Oct 2006 18:00:06 +0000
Subject: note 70067 deleted from function.number-format by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117957@lists.php.net to get a copy of this message
Note Submitter: chunket at aogos dot com ---- number_format will round up the number but i dont want it to be rounded up. i couldnt find a solution on the web. so i figured out on my own. below is a simple solution. for example $num = "66,666.666666"; //if use round, number_format or float $result = number_format($num,1); //66,666.7 //usage function roundPrecise($num, $dec) { $ex = explode(".",$num); $num = number_format($ex[0].".".substr($ex[1],0,$dec),$dec); return $num; } $result = roundPrecise($num,1); //66,666.6

« previous php.notes (#117957) next »