note 76841 added to function.number-format
| From: | JasonJohnson at osu1 dot php dot net | Date: | Wed, 01 Aug 2007 19:39:40 +0000 |
| Subject: | note 76841 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129112@lists.php.net to get a copy of this message | ||
Beware of this pitfall:
$value = number_format ($float_val, 2, ".");
This will silently return an empty string and not throw an error, at least with PHP 5.x.
This is the corrected code:
$value = number_format ($float_val, 2, ".", ",");
- or -
$value = number_format ($float_val, 2);
You must specifiy either the decimal point AND thousands separator else neither, otherwise
you'll run into this issue.
I just spent over 30min debugging code with this problem!
----
Server IP: 208.69.120.35
Probable Submitter: 166.129.83.175
----
Manual Page -- http://www.php.net/manual/en/function.number-format.php
Edit -- https://master.php.net/note/edit/76841
Del: integrated -- https://master.php.net/note/delete/76841/integrated
Del: useless -- https://master.php.net/note/delete/76841/useless
Del: bad code -- https://master.php.net/note/delete/76841/bad+code
Del: spam -- https://master.php.net/note/delete/76841/spam
Del: non-english -- https://master.php.net/note/delete/76841/non-english
Del: in docs -- https://master.php.net/note/delete/76841/in+docs
Del: other reasons-- https://master.php.net/note/delete/76841
Reject -- https://master.php.net/note/reject/76841
Search -- https://master.php.net/manage/user-notes.php