From f47dbb6a58159993b37974c85a3cc9f1c00fa1e0 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 15 Aug 2020 14:11:37 -0400 Subject: [PATCH] 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.) --- AK/NumberFormat.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AK/NumberFormat.h b/AK/NumberFormat.h index 4fbb8d009a..2b69c16858 100644 --- a/AK/NumberFormat.h +++ b/AK/NumberFormat.h @@ -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"); } }