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
Notes:
sideshowbarker
2024-07-19 03:34:35 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/f47dbb6a581 Pull-request: https://github.com/SerenityOS/serenity/pull/3164 Reviewed-by: https://github.com/Dexesttp Reviewed-by: https://github.com/alimpfard
1 changed files with 4 additions and 4 deletions
|
@ -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…
Add table
Reference in a new issue