1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:42:57 +08:00

Merge pull request #23679 from cdwcgt/percentage-format-slider

Format percentage based on significant decimal digits
This commit is contained in:
Bartłomiej Dach 2023-05-29 21:18:23 +02:00 committed by GitHub
commit 36f60def6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,14 +89,16 @@ 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)
{
return floatValue.ToString($@"P{Math.Max(0, significantDigits - 2)}");
}
string negativeSign = Math.Round(floatValue, significantDigits) < 0 ? "-" : string.Empty;
return $"{negativeSign}{Math.Abs(floatValue).ToString($"N{significantDigits}")}";