note 99179 added to function.number-format
| From: | Anonymous at osu1 dot php dot net | Date: | Sun, 01 Aug 2010 09:24:50 +0000 |
| Subject: | note 99179 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171296@lists.php.net to get a copy of this message | ||
This is a bug from 5.3.2, not sure if it was fixed in 5.3.3
number_format fails to return anything when a keyed array is passed to it to be formatted.
Warning: number_format() expects parameter 1 to be double, object given in .... on line ....
<?php
$array['test'] = 10567987.23;
function num_format($num, $rnd = 2) {
$num = trim($num);
return number_format($num,$rnd,'.',',');
}
//always dies silently with warning if enabled
echo number_format($array['test'],2,'.',',')."<br
/>\n";
//works fine in php 5.3.2
echo num_format($array['test'])."<br />\n";
?>
Added a trim() and number_format handles it fine in the short quick-fix function....
So, number_format is adding a whitespace around the number passed to it from an array key...
----
Server IP: 69.147.83.197
Probable Submitter: 71.97.158.4
----
Manual Page -- http://www.php.net/manual/en/function.number-format.php
Edit -- https://master.php.net/note/edit/99179
Del: integrated -- https://master.php.net/note/delete/99179/integrated
Del: useless -- https://master.php.net/note/delete/99179/useless
Del: bad code -- https://master.php.net/note/delete/99179/bad+code
Del: spam -- https://master.php.net/note/delete/99179/spam
Del: non-english -- https://master.php.net/note/delete/99179/non-english
Del: in docs -- https://master.php.net/note/delete/99179/in+docs
Del: other reasons-- https://master.php.net/note/delete/99179
Reject -- https://master.php.net/note/reject/99179
Search -- https://master.php.net/manage/user-notes.php