diff options
Diffstat (limited to 'includes/common.inc')
-rw-r--r-- | includes/common.inc | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/includes/common.inc b/includes/common.inc index bdf3d1867..883371ff4 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1079,17 +1079,21 @@ function parse_size($size) { * A translated string representation of the size. */ function format_size($size, $langcode = NULL) { - if ($size < 1024) { + if ($size < 1000) { return format_plural($size, '1 byte', '@count bytes', array(), $langcode); } else { - $size = round($size / 1024, 2); - $suffix = t('KB', array(), $langcode); - if ($size >= 1024) { - $size = round($size / 1024, 2); - $suffix = t('MB', array(), $langcode); + $size = $size / 1000; // convert bytes to kilobytes (1000 bytes) + $units = array('KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); + foreach ($units as $suffix) { + if (round($size, 2) >= 1000) { + $size = $size / 1000; + } + else { + break; + } } - return t('@size @suffix', array('@size' => $size, '@suffix' => $suffix), $langcode); + return t('@size @suffix', array('@size' => round($size, 2), '@suffix' => $suffix), $langcode); } } |