From eca5549602dc9d51fb4ac0c3273033285bb1372b Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 4 Feb 2015 08:18:43 +0100 Subject: [PATCH] StringForRate: change the threshold for unit change. We would show "1Mbps" for 1.0 to 1.9 actual speed, which made this not so helpful. Instead, switch to Mbps when reaching 10000 Kbps. So we show "1000 Kbps" or 1900Kbps" in the mentionned situation, and up to "9999 Kbps" (note this is still only 4 digits, so it stays readable). We then switch to "10 Mbps", which is still only withing 12% of the actual speed (but better than the previous error of up to 50%). Fixes #11821. Also use uppercase for the SI prefixes as it should be, and use %d instead of %f for the bps rating as it is an integer. --- src/kits/shared/StringForRate.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/kits/shared/StringForRate.cpp b/src/kits/shared/StringForRate.cpp index 4f0c163526..a2d3f57a6f 100644 --- a/src/kits/shared/StringForRate.cpp +++ b/src/kits/shared/StringForRate.cpp @@ -23,34 +23,34 @@ const char* string_for_rate(double rate, char* string, size_t stringSize, double base) { double kbps = rate / base; - if (kbps < 1.0) { - const char* trKey = B_TRANSLATE_MARK("%.0f bps"); + if (kbps < 10.0) { + const char* trKey = B_TRANSLATE_MARK("%d bps"); snprintf(string, stringSize, gSystemCatalog.GetString(trKey, B_TRANSLATION_CONTEXT), (int)rate); return string; } double mbps = kbps / base; - if (mbps < 1.0) { - const char* trKey = B_TRANSLATE_MARK("%.0f kbps"); + if (mbps < 10.0) { + const char* trKey = B_TRANSLATE_MARK("%.0f Kbps"); snprintf(string, stringSize, gSystemCatalog.GetString(trKey, B_TRANSLATION_CONTEXT), kbps); return string; } double gbps = mbps / base; - if (gbps < 1.0) { - const char* trKey = B_TRANSLATE_MARK("%.0f mbps"); + if (gbps < 10.0) { + const char* trKey = B_TRANSLATE_MARK("%.0f Mbps"); snprintf(string, stringSize, gSystemCatalog.GetString(trKey, B_TRANSLATION_CONTEXT), mbps); return string; } double tbps = gbps / base; - if (tbps < 1.0) { - const char* trKey = B_TRANSLATE_MARK("%.0f gbps"); + if (tbps < 10.0) { + const char* trKey = B_TRANSLATE_MARK("%.0f Gbps"); snprintf(string, stringSize, gSystemCatalog.GetString(trKey, B_TRANSLATION_CONTEXT), gbps); return string; } - const char* trKey = B_TRANSLATE_MARK("%.0f tbps"); + const char* trKey = B_TRANSLATE_MARK("%.0f Tbps"); snprintf(string, stringSize, gSystemCatalog.GetString(trKey, B_TRANSLATION_CONTEXT), tbps); return string;