代表数字像SO一样缩短(13500 => 13.5k)?

Ok I write my own JS code for this bug I'm sure there's something more comprehensive out there I can use. My Google mojo isn't working though - any help finding open source code that'll help me represent numbers like how SO does for high numbers (102500 => 102.5K, 18601 => 18.6K, etc)?

JS or PHP would be awesome, otherwise I can translate.

Thanks!

This will give you a really good example of how to do exactly that: http://www.jonasjohn.de/snippets/php/readable-filesize.htm

The link is for megabytes but if you want it for thousands just change the $mod variable and change the names that are given. Then it will fit your purposes perfectly.

Or directly check

Human readable file sizes

Codepaste

/**
 * Return human readable sizes
 *
 * @author      Aidan Lister <aidan@php.net>
 * @version     1.3.0
 * @link        http://aidanlister.com/repos/v/function.size_readable.php
 * @param       int     $size        size in bytes
 * @param       string  $max         maximum unit
 * @param       string  $system      'si' for SI, 'bi' for binary prefixes
 * @param       string  $retstring   return string format
 */
function size_readable($size, $max = null, $system = 'si', $retstring = '%01.2f %s')
{
    // Pick units
    $systems['si']['prefix'] = array('B', 'K', 'MB', 'GB', 'TB', 'PB');
    $systems['si']['size']   = 1000;
    $systems['bi']['prefix'] = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
    $systems['bi']['size']   = 1024;
    $sys = isset($systems[$system]) ? $systems[$system] : $systems['si'];

    // Max unit to display
    $depth = count($sys['prefix']) - 1;
    if ($max && false !== $d = array_search($max, $sys['prefix'])) {
        $depth = $d;
    }

    // Loop
    $i = 0;
    while ($size >= $sys['size'] && $i < $depth) {
        $size /= $sys['size'];
        $i++;
    }

    return sprintf($retstring, $size, $sys['prefix'][$i]);
}