mind is drawing a blank help please

Discussion in 'PHP' started by lowridertj, Oct 4, 2010.

  1. #1
    I want to take numbers as shown below and shorten them down.

    5,877,210,367,380 to 5.87TR
    *for 5.87 trillion

    5,877,210,367 to 5.87B
    *for 5.87 billion

    5,877,210 to 5.87M
    *for 5.87 million

    5,877 to 5.87T
    *for 5.87 thousand


    Any ideas how to perform this with php and example would be great. To late for me tonight and cant seem to wrap my head around it.

    Thanks,
    TJ
     
    lowridertj, Oct 4, 2010 IP
  2. veroxii

    veroxii Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    function humanSizes($bytes) {
    $type = array("", "kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta");
    $idx = 0;

    while($bytes >= 1024)
    {
    $bytes /= 1024;
    $idx++;
    }

    return("".round($bytes, 2)." ".$type[$idx]."bytes");
    }

    I'm sure you can work it out similarly for trillion, million, thousand...
     
    veroxii, Oct 5, 2010 IP