forked from mirror/pixelfed
Update PrettyNumber, add decimal option
This commit is contained in:
parent
28df9f7e80
commit
84520fe103
1 changed files with 2 additions and 2 deletions
|
@ -4,7 +4,7 @@ namespace App\Util\Lexer;
|
||||||
|
|
||||||
class PrettyNumber
|
class PrettyNumber
|
||||||
{
|
{
|
||||||
public static function convert($number)
|
public static function convert($number, $showDecimals = true)
|
||||||
{
|
{
|
||||||
if(!is_integer($number)) {
|
if(!is_integer($number)) {
|
||||||
return $number;
|
return $number;
|
||||||
|
@ -14,7 +14,7 @@ class PrettyNumber
|
||||||
foreach ($abbrevs as $exponent => $abbrev) {
|
foreach ($abbrevs as $exponent => $abbrev) {
|
||||||
if(abs($number) >= pow(10, $exponent)) {
|
if(abs($number) >= pow(10, $exponent)) {
|
||||||
$display = $number / pow(10, $exponent);
|
$display = $number / pow(10, $exponent);
|
||||||
$decimals = ($exponent >= 3 && round($display) < 100) ? 1 : 0;
|
$decimals = !$showDecimals ? 0 : ($exponent >= 3 && round($display) < 100) ? 1 : 0;
|
||||||
$number = number_format($display, $decimals).$abbrev;
|
$number = number_format($display, $decimals).$abbrev;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue