mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 14:42:56 +08:00
Format percentage based on significant decimal digits
This commit is contained in:
parent
06ea8efb16
commit
89c8ef3c9b
@ -89,14 +89,20 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
double floatValue = value.ToDouble(NumberFormatInfo.InvariantInfo);
|
||||
|
||||
if (DisplayAsPercentage)
|
||||
return floatValue.ToString("0%");
|
||||
|
||||
decimal decimalPrecision = normalise(CurrentNumber.Precision.ToDecimal(NumberFormatInfo.InvariantInfo), max_decimal_digits);
|
||||
|
||||
// Find the number of significant digits (we could have less than 5 after normalize())
|
||||
int significantDigits = FormatUtils.FindPrecision(decimalPrecision);
|
||||
|
||||
if (DisplayAsPercentage)
|
||||
{
|
||||
if (significantDigits <= 2)
|
||||
return floatValue.ToString("0%");
|
||||
|
||||
string format = "0." + new string('0', significantDigits - 2) + "%";
|
||||
return floatValue.ToString(format);
|
||||
}
|
||||
|
||||
string negativeSign = Math.Round(floatValue, significantDigits) < 0 ? "-" : string.Empty;
|
||||
|
||||
return $"{negativeSign}{Math.Abs(floatValue).ToString($"N{significantDigits}")}";
|
||||
|
Loading…
Reference in New Issue
Block a user