diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-06-09 08:11:45 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-06-09 08:11:45 +0000 |
commit | ecb032a239f88ead2087aa98cbcf28522a523922 (patch) | |
tree | 042c9109c3fc8149857262be521c25c00337d973 /includes/common.inc | |
parent | 5a9b7c5b713bdd009846d80b3f24caf9948d6fc9 (diff) | |
download | brdo-ecb032a239f88ead2087aa98cbcf28522a523922.tar.gz brdo-ecb032a239f88ead2087aa98cbcf28522a523922.tar.bz2 |
- Patch #151902 by MadHarold et al: a better format_size() (and removed some excessive white space).
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); } } |