mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
Add PrettyNumber util
This commit is contained in:
parent
1566141f68
commit
27e779b08d
1 changed files with 20 additions and 0 deletions
20
app/Util/Lexer/PrettyNumber.php
Normal file
20
app/Util/Lexer/PrettyNumber.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Util\Lexer;
|
||||
|
||||
class PrettyNumber {
|
||||
|
||||
public static function convert($expression)
|
||||
{
|
||||
$abbrevs = array(12 => "T", 9 => "B", 6 => "M", 3 => "K", 0 => "");
|
||||
foreach($abbrevs as $exponent => $abbrev) {
|
||||
if($expression >= pow(10, $exponent)) {
|
||||
$display_num = $expression / pow(10, $exponent);
|
||||
$num = number_format($display_num,0) . $abbrev;
|
||||
return $num;
|
||||
}
|
||||
}
|
||||
return $expression;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue