mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-22 10:36:24 +00:00
AK: Use IEC prefixes in human_readable_format
Windows uses "KB", "MB", "GB" as powers of two. macOS uses "kB", "MB", "GB" as powers of ten. "k", "M", "G" are standard SI prefixes that normally refer to powers of ten. The IEC introduced "KiB", "MiB", "GiB" to unambiguously refer to powers of two. It admittedly hasn't caught on that much, but it does have the advantage that it's unabigious what it means. So let's use it for user-visible sizes in SerenityOS. (Linux does all of the above in different places, depending on app and toolkit.)
This commit is contained in:
parent
aa97166739
commit
f47dbb6a58
|
@ -41,12 +41,12 @@ static String number_string_with_one_decimal(float number, const char* suffix)
|
|||
static String human_readable_size(size_t size)
|
||||
{
|
||||
if (size < 1 * KiB)
|
||||
return String::format("%zu bytes", size);
|
||||
return String::format("%zu B", size);
|
||||
if (size < 1 * MiB)
|
||||
return number_string_with_one_decimal((float)size / (float)KiB, "KB");
|
||||
return number_string_with_one_decimal((float)size / (float)KiB, "KiB");
|
||||
if (size < 1 * GiB)
|
||||
return number_string_with_one_decimal((float)size / (float)MiB, "MB");
|
||||
return number_string_with_one_decimal((float)size / (float)GiB, "GB");
|
||||
return number_string_with_one_decimal((float)size / (float)MiB, "MiB");
|
||||
return number_string_with_one_decimal((float)size / (float)GiB, "GiB");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue