From 066d65549350a05f0f48c5186ca5d807ffb9c46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Tue, 14 Mar 2023 03:43:39 +0800 Subject: [PATCH] fix: precision in stringForSpeedCompact (#5213) --- macosx/NSStringAdditions.mm | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/macosx/NSStringAdditions.mm b/macosx/NSStringAdditions.mm index a3dc93e66..ded7c5c11 100644 --- a/macosx/NSStringAdditions.mm +++ b/macosx/NSStringAdditions.mm @@ -188,10 +188,8 @@ { return [NSString localizedStringWithFormat:@"%.2f %@", speed, gb]; } - else // insane speeds - { - return [NSString localizedStringWithFormat:@"%.1f %@", speed, gb]; - } + // 100.0 GB/s and above + return [NSString localizedStringWithFormat:@"%.1f %@", speed, gb]; } + (NSString*)stringForSpeedCompact:(CGFloat)speed kb:(NSString*)kb mb:(NSString*)mb gb:(NSString*)gb @@ -200,14 +198,14 @@ { return [NSString localizedStringWithFormat:@"%.1f %@", speed, kb]; } - if (speed < 999.95) // 100 KB/s to 999 KB/s + if (speed < 999.5) // 100 KB/s to 999 KB/s { return [NSString localizedStringWithFormat:@"%.0f %@", speed, kb]; } speed /= 1000.0; - if (speed < 9.95) // 1.00 MB/s to 9.99 MB/s + if (speed < 9.995) // 1.00 MB/s to 9.99 MB/s { return [NSString localizedStringWithFormat:@"%.2f %@", speed, mb]; } @@ -215,14 +213,14 @@ { return [NSString localizedStringWithFormat:@"%.1f %@", speed, mb]; } - if (speed < 999.95) // 100 MB/s to 999 MB/s + if (speed < 999.5) // 100 MB/s to 999 MB/s { return [NSString localizedStringWithFormat:@"%.0f %@", speed, mb]; } speed /= 1000.0; - if (speed < 9.95) // 1.00 GB/s to 9.99 GB/s + if (speed < 9.995) // 1.00 GB/s to 9.99 GB/s { return [NSString localizedStringWithFormat:@"%.2f %@", speed, gb]; } @@ -230,10 +228,8 @@ { return [NSString localizedStringWithFormat:@"%.1f %@", speed, gb]; } - else // insane speeds - { - return [NSString localizedStringWithFormat:@"%.0f %@", speed, gb]; - } + // 100 GB/s and above + return [NSString localizedStringWithFormat:@"%.0f %@", speed, gb]; } @end