mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 13:23:05 +08:00
Add FormatUtils.FormatAccuracy and usages
This commit is contained in:
parent
ddf9317bec
commit
a8ce50fadd
@ -13,6 +13,7 @@ using osu.Game.Rulesets;
|
|||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
using osu.Game.Utils;
|
||||||
|
|
||||||
namespace osu.Game.Scoring
|
namespace osu.Game.Scoring
|
||||||
{
|
{
|
||||||
@ -32,7 +33,7 @@ namespace osu.Game.Scoring
|
|||||||
public double Accuracy { get; set; }
|
public double Accuracy { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string DisplayAccuracy => Accuracy == 1 ? "100%" : $"{Accuracy:0.00%}";
|
public string DisplayAccuracy => Accuracy.FormatAccuracy();
|
||||||
|
|
||||||
[JsonProperty(@"pp")]
|
[JsonProperty(@"pp")]
|
||||||
public double? PP { get; set; }
|
public double? PP { get; set; }
|
||||||
|
@ -5,6 +5,7 @@ using System;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using static osu.Game.Users.User;
|
using static osu.Game.Users.User;
|
||||||
|
using osu.Game.Utils;
|
||||||
|
|
||||||
namespace osu.Game.Users
|
namespace osu.Game.Users
|
||||||
{
|
{
|
||||||
@ -44,7 +45,7 @@ namespace osu.Game.Users
|
|||||||
public decimal Accuracy;
|
public decimal Accuracy;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string DisplayAccuracy => $"{Accuracy:0.00%}";
|
public string DisplayAccuracy => Accuracy.FormatAccuracy();
|
||||||
|
|
||||||
[JsonProperty(@"play_count")]
|
[JsonProperty(@"play_count")]
|
||||||
public int PlayCount;
|
public int PlayCount;
|
||||||
|
21
osu.Game/Utils/FormatUtils.cs
Normal file
21
osu.Game/Utils/FormatUtils.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
namespace osu.Game.Utils
|
||||||
|
{
|
||||||
|
public static class FormatUtils
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Turns the provided accuracy into a percentage with 2 decimal places.
|
||||||
|
/// 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>
|
||||||
|
public static string FormatAccuracy(this double accuracy) => accuracy == 1 ? "100%" : $"{accuracy:0.00%}";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Turns the provided accuracy into a percentage with 2 decimal places.
|
||||||
|
/// 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>
|
||||||
|
public static string FormatAccuracy(this decimal accuracy) => accuracy == 100 ? "100%" : $"{accuracy:0.00}%";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user