1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 04:47:24 +08:00
osu-lazer/osu.Game/Utils/FormatUtils.cs

31 lines
1.1 KiB
C#
Raw Normal View History

2020-02-04 12:18:19 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2020-12-19 22:02:56 +08:00
using Humanizer;
namespace osu.Game.Utils
{
2020-02-04 12:36:22 +08:00
public static class FormatUtils
{
/// <summary>
/// Turns the provided accuracy into a percentage with 2 decimal places.
/// </summary>
/// <param name="accuracy">The accuracy to be formatted</param>
/// <returns>formatted accuracy in percentage</returns>
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;
return $"{accuracy:0.00%}";
}
2020-12-19 22:02:56 +08:00
/// <summary>
/// Formats the supplied rank/leaderboard position in a consistent, simplified way.
/// </summary>
/// <param name="rank">The rank/position to be formatted.</param>
public static string FormatRank(this int rank) => rank.ToMetric(decimals: rank < 100_000 ? 1 : 0);
2020-02-04 12:36:22 +08:00
}
}