note 123879 added to function.number-format
| From: | mail at igor dot vodka | Date: | Thu, 23 May 2019 11:56:35 +0000 |
| Subject: | note 123879 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-211112@lists.php.net to get a copy of this message | ||
Please be careful with stm555 at hotmail dot com's solution.
If you pass some little negative number (-1 < $number < 0) such as -0.01, the integer part
would be converted to 0, so that the sign is eventually lost.
Here is a fixed version:
<?php
function number_format_unlimited_precision($number,$decimal = '.')
{
$broken_number = explode('.', abs($number));
$sign = $number < 0 ? '-' : '';
return $sign.number_format($broken_number[0]).$decimal.$broken_number[1];
}
?>
----
Server IP: 208.43.231.9
Probable Submitter: 185.85.3.134 (proxied: 2a00:1370:8136:13d9:5d30:9a08:1baf:7249)
----
Manual Page -- http://php.net/manual/en/function.number-format.php
Edit -- https://master.php.net/note/edit/123879
Del: integrated -- https://master.php.net/note/delete/123879/integrated
Del: useless -- https://master.php.net/note/delete/123879/useless
Del: bad code -- https://master.php.net/note/delete/123879/bad+code
Del: spam -- https://master.php.net/note/delete/123879/spam
Del: non-english -- https://master.php.net/note/delete/123879/non-english
Del: in docs -- https://master.php.net/note/delete/123879/in+docs
Del: other reasons-- https://master.php.net/note/delete/123879
Reject -- https://master.php.net/note/reject/123879
Search -- https://master.php.net/manage/user-notes.php