osu/osu.Game/Utils/FormatUtils.cs

25 lines
1.1 KiB
C#
Raw Normal View History

2020-02-04 04:18:19 +00: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.
namespace osu.Game.Utils
{
2020-02-04 04:36:22 +00:00
public static class FormatUtils
{
/// <summary>
/// Turns the provided accuracy into a percentage with 2 decimal places.
2020-02-04 04:36:22 +00:00
/// Omits all decimal places when <paramref name="accuracy"/> equals 1d.
/// </summary>
/// <param name="accuracy">The accuracy to be formatted</param>
/// <returns>formatted accuracy in percentage</returns>
2020-02-04 04:36:22 +00:00
public static string FormatAccuracy(this double accuracy) => accuracy == 1 ? "100%" : $"{accuracy:0.00%}";
2020-02-04 04:36:22 +00:00
/// <summary>
/// Turns the provided accuracy into a percentage with 2 decimal places.
2020-02-04 04:36:22 +00:00
/// Omits all decimal places when <paramref name="accuracy"/> equals 100m.
/// </summary>
/// <param name="accuracy">The accuracy to be formatted</param>
/// <returns>formatted accuracy in percentage</returns>
2020-02-04 04:36:22 +00:00
public static string FormatAccuracy(this decimal accuracy) => accuracy == 100 ? "100%" : $"{accuracy:0.00}%";
}
}