1. Go to this page and download the library: Download stonec0der/shorten-nums library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stonec0der / shorten-nums example snippets
use Stonec0der\ShortenNumsFacade
...
$value = '12894090';
// Shorten
$formated_number = ShortenNumsFacade::readableNumber($value);
// Output will
// 12.9M.
/*
Default
This enable you to return for 1240 => 1.2K with default precisionn
and 1.24 with $precision set to 2 and so on.
*/
$value = '1240';
$precision = 2;
$formated_number = ShortenNumsFacade::readableNumber($value, $precision);
// Output
// 1.24K