note 126733 added to function.number-format
| From: | info at ensostudio dot ru | Date: | Fri, 31 Dec 2021 02:44:07 +0000 |
| Subject: | note 126733 added to function.number-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217446@lists.php.net to get a copy of this message | ||
Auto calculate decimals by default:
<?php
function numberFormat(
float $num,
int $decimals = -1,
?string $decimalSeparator = '.',
?string $thousandsSeparator = ''
): string {
if ($decimals < 0) {
$intNum = (int) $num;
if ($num == $intNum) {
$decimals = 0;
} else {
$decimals = strlen($num) - strlen($intNum) - 1;
}
}
return number_format($num, $decimals, $decimalSeparator, $thousandsSeparator);
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 31.129.215.166)
----
Manual Page -- https://php.net/manual/en/function.number-format.php
Edit -- https://main.php.net/note/edit/126733
Del: integrated -- https://main.php.net/note/delete/126733/integrated
Del: useless -- https://main.php.net/note/delete/126733/useless
Del: bad code -- https://main.php.net/note/delete/126733/bad+code
Del: spam -- https://main.php.net/note/delete/126733/spam
Del: non-english -- https://main.php.net/note/delete/126733/non-english
Del: in docs -- https://main.php.net/note/delete/126733/in+docs
Del: other reasons-- https://main.php.net/note/delete/126733
Reject -- https://main.php.net/note/reject/126733
Search -- https://main.php.net/manage/user-notes.php