note 95293 added to function.number-format

From: Date: Thu, 24 Dec 2009 17:10:15 +0000
Subject: note 95293 added to function.number-format
Groups: php.notes 
Request: Send a blank email to php-notes+get-164304@lists.php.net to get a copy of this message
number_format is deficient in the sense that it is currently unable to output numbers in japanese format (grouping algarisms in tens of thousands instead of thousands). The alternative below will work just like number_format, but the added $group parameter allows to change how many algarisms per group the output will have. <?php function numberFormat ($number , $decimals = 2 , $dec_point = '.' , $sep = ',', $group=3 ){ $num = sprintf("%0.{$decimals}f",$number); $num = explode('.',$num); while (strlen($num[0]) % $group) $num[0]= ' '.$num[0]; $num[0] = str_split($num[0],$group); $num[0] = join($sep[0],$num[0]); $num[0] = trim($num[0]); $num = join($dec_point[0],$num); return $num; } echo numberformat(123456789,0,'.',' ',4); // 1 2345 6789 ?> ---- Server IP: 187.16.23.128 Probable Submitter: 189.107.55.249 ---- Manual Page -- http://www.php.net/manual/en/function.number-format.php Edit -- https://master.php.net/note/edit/95293 Del: integrated -- https://master.php.net/note/delete/95293/integrated Del: useless -- https://master.php.net/note/delete/95293/useless Del: bad code -- https://master.php.net/note/delete/95293/bad+code Del: spam -- https://master.php.net/note/delete/95293/spam Del: non-english -- https://master.php.net/note/delete/95293/non-english Del: in docs -- https://master.php.net/note/delete/95293/in+docs Del: other reasons-- https://master.php.net/note/delete/95293 Reject -- https://master.php.net/note/reject/95293 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164304) next »