From 6a7f9261684602ab3b4633839a1bea1e0acd035c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 26 Mar 2021 13:06:30 +0900 Subject: [PATCH] Change rounding to use a more general flooring approach --- osu.Game.Tests/NonVisual/FormatUtilsTest.cs | 2 +- osu.Game/Utils/FormatUtils.cs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/NonVisual/FormatUtilsTest.cs b/osu.Game.Tests/NonVisual/FormatUtilsTest.cs index eb738f5f67..46d8f4fec4 100644 --- a/osu.Game.Tests/NonVisual/FormatUtilsTest.cs +++ b/osu.Game.Tests/NonVisual/FormatUtilsTest.cs @@ -12,7 +12,7 @@ namespace osu.Game.Tests.NonVisual [TestCase(0, "0.00%")] [TestCase(0.01, "1.00%")] [TestCase(0.9899, "98.99%")] - [TestCase(0.989999, "99.00%")] + [TestCase(0.989999, "98.99%")] [TestCase(0.99, "99.00%")] [TestCase(0.9999, "99.99%")] [TestCase(0.999999, "99.99%")] diff --git a/osu.Game/Utils/FormatUtils.cs b/osu.Game/Utils/FormatUtils.cs index 4c7702f04e..8312b9e756 100644 --- a/osu.Game/Utils/FormatUtils.cs +++ b/osu.Game/Utils/FormatUtils.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using Humanizer; namespace osu.Game.Utils @@ -14,9 +15,11 @@ namespace osu.Game.Utils /// formatted accuracy in percentage public static string FormatAccuracy(this double accuracy) { - // we don't ever want to show 100% when the accuracy is below perfect, even if it rounds to 100%. - if (accuracy < 1 && accuracy > 0.9999) - accuracy = 0.9999; + // for the sake of display purposes, we don't want to show a user a "rounded up" percentage to the next whole number. + // ie. a score which gets 89.99999% shouldn't ever show as 90%. + // the reasoning for this is that cutoffs for grade increases are at whole numbers and displaying the required + // percentile with a non-matching grade is confusing. + accuracy = Math.Floor(accuracy * 10000) / 10000; return $"{accuracy:0.00%}"; }