note 108456 added to function.number-format

From: Date: Fri, 27 Apr 2012 14:26:26 +0000
Subject: note 108456 added to function.number-format
Groups: php.notes 
Request: Send a blank email to php-notes+get-187379@lists.php.net to get a copy of this message
As many people state the number_format function will round. Now if your like me and you don't want stuff to round (and the functions below do not work for you) you can try a little regex: function convert_size_human($size){ $unit=array('','KB','MB','GB','TB','PB'); $byte_size = $size/pow(1024,($i=floor(log($size,1024)))); if(is_really_int($byte_size)){ return $byte_size.' '.$unit[$i]; }else{ preg_match('/^[0-9]+\.[0-9]{2}/', $byte_size, $matches); return $matches[0].' '.$unit[$i]; } } The regex used when the number is not an int ensures that 3.99887 GB comes out as 3.99 GB instead of 4GB as it does from number_format or the functions below. ---- Server IP: 92.48.74.199 Probable Submitter: 81.187.108.206 ---- Manual Page -- http://www.php.net/manual/en/function.number-format.php Edit -- https://master.php.net/note/edit/108456 Del: integrated -- https://master.php.net/note/delete/108456/integrated Del: useless -- https://master.php.net/note/delete/108456/useless Del: bad code -- https://master.php.net/note/delete/108456/bad+code Del: spam -- https://master.php.net/note/delete/108456/spam Del: non-english -- https://master.php.net/note/delete/108456/non-english Del: in docs -- https://master.php.net/note/delete/108456/in+docs Del: other reasons-- https://master.php.net/note/delete/108456 Reject -- https://master.php.net/note/reject/108456 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#187379) next »