note 70067 added to function.number-format

From: Date: Mon, 02 Oct 2006 07:20:05 +0000
Subject: note 70067 added to function.number-format
Groups: php.notes 
Request: Send a blank email to php-notes+get-117929@lists.php.net to get a copy of this message
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 ---- Server IP: 202.157.183.147 Probable Submitter: 58.26.17.51 ---- Manual Page -- http://www.php.net/manual/en/function.number-format.php Edit -- https://master.php.net/note/edit/70067 Del: integrated -- https://master.php.net/note/delete/70067/integrated Del: useless -- https://master.php.net/note/delete/70067/useless Del: bad code -- https://master.php.net/note/delete/70067/bad+code Del: spam -- https://master.php.net/note/delete/70067/spam Del: non-english -- https://master.php.net/note/delete/70067/non-english Del: in docs -- https://master.php.net/note/delete/70067/in+docs Del: other reasons-- https://master.php.net/note/delete/70067 Reject -- https://master.php.net/note/reject/70067 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117929) next »