You are here

function dba_report_short in Database Administration 7

Format number.

1 call to dba_report_short()
dba_mysql_report_output in database/mysql.report.inc
Build mysqlreport output.

File

./dba.report.inc, line 61

Code

function dba_report_short($number, $kb = FALSE, $d = 2) {
  $n = 0;
  $format = array();
  if ($kb) {
    $format = array(
      'b',
      'Kb',
      'Mb',
      'Gb',
      'Tb',
    );
    while ($number > 1023) {
      $number /= 1024;
      $n++;
    }
  }
  else {
    $format = array(
      '',
      'K',
      'M',
      'G',
      'T',
    );
    while ($number > 999) {
      $number /= 1000;
      $n++;
    }
  }
  $short = sprintf("%.{$d}f%s", $number, $format[$n]);
  if (preg_match('/^(.+)\\.00$/', $short, $matches)) {
    return $matches[1];

    // Convert 12.00 to 12, but not 12.00kb to 12kb
  }
  return $short;
}