function backup_migrate_format_size in Backup and Migrate 7.3
Same name and namespace in other branches
- 8.3 backup_migrate.module \backup_migrate_format_size()
Format a size, treating 1GB as 1000 MB rather than 1024 MB.
This is a more standard and expected version for storage (as opposed to memory).
File
- ./
backup_migrate.module, line 2074 - Backup and restore databases for Drupal.
Code
function backup_migrate_format_size($size, $langcode = LANGUAGE_NONE) {
$precision = 2;
$multiply = pow(10, $precision);
if ($size == 0) {
return t('0 bytes', array(), array(
'langcode' => $langcode,
));
}
if ($size < 1024) {
return format_plural($size, '1 byte', '@count bytes', array(), array(
'langcode' => $langcode,
));
}
else {
$size = ceil($size * $multiply / 1024);
$string = '@size KB';
if ($size >= 1024 * $multiply) {
$size = ceil($size / 1024);
$string = '@size MB';
}
if ($size >= 1000 * $multiply) {
$size = ceil($size / 1000);
$string = '@size GB';
}
if ($size >= 1000 * $multiply) {
$size = ceil($size / 1000);
$string = '@size TB';
}
return t($string, array(
'@size' => round($size / $multiply, $precision),
), array(
'langcode' => $langcode,
));
}
}