diff --git a/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs b/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs index 9d71c3267d..e0705e4bbb 100644 --- a/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Catch/Mods/CatchModDifficultyAdjust.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using System.Globalization; using osu.Framework.Bindables; using osu.Framework.Localisation; using osu.Game.Beatmaps; @@ -53,7 +52,7 @@ namespace osu.Game.Rulesets.Catch.Mods return string.Empty; string format(string acronym, DifficultyBindable bindable) - => $"{acronym}{bindable.Value!.Value.ToStandardFormattedString(1, cultureInfo: CultureInfo.InvariantCulture)}"; + => $"{acronym}{bindable.Value!.Value.ToStandardFormattedString(1)}"; } } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs b/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs index 906502d498..0d6b02a7d1 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModDifficultyAdjust.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using System.Globalization; using osu.Framework.Bindables; using osu.Framework.Localisation; using osu.Game.Beatmaps; @@ -53,7 +52,7 @@ namespace osu.Game.Rulesets.Osu.Mods return string.Empty; string format(string acronym, DifficultyBindable bindable) - => $"{acronym}{bindable.Value!.Value.ToStandardFormattedString(1, cultureInfo: CultureInfo.InvariantCulture)}"; + => $"{acronym}{bindable.Value!.Value.ToStandardFormattedString(1)}"; } } diff --git a/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs b/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs index 538fcfc386..87d7aabf86 100644 --- a/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs +++ b/osu.Game.Rulesets.Taiko/Mods/TaikoModDifficultyAdjust.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using System.Globalization; using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Configuration; @@ -36,7 +35,7 @@ namespace osu.Game.Rulesets.Taiko.Mods return string.Empty; string format(string acronym, DifficultyBindable bindable, int digits) - => $"{acronym}{bindable.Value!.Value.ToStandardFormattedString(digits, cultureInfo: CultureInfo.InvariantCulture)}"; + => $"{acronym}{bindable.Value!.Value.ToStandardFormattedString(digits)}"; } } diff --git a/osu.Game.Tests/Extensions/NumberFormattingExtensionsTest.cs b/osu.Game.Tests/Extensions/NumberFormattingExtensionsTest.cs index 7d3a8ccc60..f60c978788 100644 --- a/osu.Game.Tests/Extensions/NumberFormattingExtensionsTest.cs +++ b/osu.Game.Tests/Extensions/NumberFormattingExtensionsTest.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Globalization; using NUnit.Framework; using osu.Game.Extensions; @@ -18,9 +17,10 @@ namespace osu.Game.Tests.Extensions [TestCase(0, true, 0, ExpectedResult = "0%")] [TestCase(1, true, 0, ExpectedResult = "1%")] [TestCase(50, true, 0, ExpectedResult = "50%")] + [SetCulture("")] // invariant culture public string TestInteger(int input, bool percent, int decimalDigits) { - return input.ToStandardFormattedString(decimalDigits, percent, CultureInfo.InvariantCulture); + return input.ToStandardFormattedString(decimalDigits, percent); } [TestCase(-1, false, 0, ExpectedResult = "-1")] @@ -40,17 +40,8 @@ namespace osu.Game.Tests.Extensions [TestCase(0.48333, true, 2, ExpectedResult = "48%")] [TestCase(0.48333, true, 4, ExpectedResult = "48.33%")] [TestCase(1, true, 0, ExpectedResult = "100%")] + [SetCulture("")] // invariant culture public string TestDouble(double input, bool percent, int decimalDigits) - { - return input.ToStandardFormattedString(decimalDigits, percent, CultureInfo.InvariantCulture); - } - - [Test] - [SetCulture("fr-FR")] - [TestCase(0.4, true, 2, ExpectedResult = "40%")] - [TestCase(1e-6, false, 6, ExpectedResult = "0,000001")] - [TestCase(0.48333, true, 4, ExpectedResult = "48,33%")] - public string TestCultureSensitivityWhenNoneSpecified(double input, bool percent, int decimalDigits) { return input.ToStandardFormattedString(decimalDigits, percent); } @@ -58,11 +49,11 @@ namespace osu.Game.Tests.Extensions [Test] [SetCulture("fr-FR")] [TestCase(0.4, true, 2, ExpectedResult = "40%")] - [TestCase(1e-6, false, 6, ExpectedResult = "0.000001")] - [TestCase(0.48333, true, 4, ExpectedResult = "48.33%")] - public string TestCultureInsensitivityWhenInvariantSpecified(double input, bool percent, int decimalDigits) + [TestCase(1e-6, false, 6, ExpectedResult = "0,000001")] + [TestCase(0.48333, true, 4, ExpectedResult = "48,33%")] + public string TestCultureSensitivity(double input, bool percent, int decimalDigits) { - return input.ToStandardFormattedString(decimalDigits, percent, CultureInfo.InvariantCulture); + return input.ToStandardFormattedString(decimalDigits, percent); } } } diff --git a/osu.Game/Extensions/NumberFormattingExtensions.cs b/osu.Game/Extensions/NumberFormattingExtensions.cs index bb4a97b3f0..0c73590808 100644 --- a/osu.Game/Extensions/NumberFormattingExtensions.cs +++ b/osu.Game/Extensions/NumberFormattingExtensions.cs @@ -13,15 +13,15 @@ namespace osu.Game.Extensions /// /// For a given numeric type, return a formatted string in the standard format we use for display everywhere. /// + /// + /// Number formatting will abide by . + /// /// The numeric value. /// The maximum number of decimals to be considered in the original value. /// Whether the output should be a percentage. For integer types, 0-100 is mapped to 0-100%; for other types 0-1 is mapped to 0-100%. - /// The culture to use when formatting the value. Defaults to if not specified. /// The formatted output. - public static string ToStandardFormattedString(this T value, int maxDecimalDigits, bool asPercentage = false, CultureInfo? cultureInfo = null) where T : struct, INumber, IMinMaxValue + public static string ToStandardFormattedString(this T value, int maxDecimalDigits, bool asPercentage = false) where T : struct, INumber, IMinMaxValue { - cultureInfo ??= CultureInfo.CurrentCulture; - double floatValue = double.CreateTruncating(value); decimal decimalPrecision = normalise(decimal.CreateTruncating(value), maxDecimalDigits); @@ -34,12 +34,12 @@ namespace osu.Game.Extensions if (value is int) floatValue /= 100; - return floatValue.ToString($@"0.{new string('0', Math.Max(0, significantDigits - 2))}%", cultureInfo); + return floatValue.ToString($@"0.{new string('0', Math.Max(0, significantDigits - 2))}%", CultureInfo.CurrentCulture); } string negativeSign = Math.Round(floatValue, significantDigits) < 0 ? "-" : string.Empty; - return $"{negativeSign}{Math.Abs(floatValue).ToString($"N{significantDigits}", cultureInfo)}"; + return $"{negativeSign}{Math.Abs(floatValue).ToString($"N{significantDigits}", CultureInfo.CurrentCulture)}"; } /// diff --git a/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs b/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs index 517ebe3747..da5f5df200 100644 --- a/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs +++ b/osu.Game/Rulesets/Mods/ModDifficultyAdjust.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Globalization; using osu.Framework.Bindables; using osu.Framework.Graphics.Sprites; using osu.Framework.Localisation; @@ -82,7 +81,7 @@ namespace osu.Game.Rulesets.Mods return string.Empty; - string format(string acronym, DifficultyBindable bindable) => $"{acronym}{bindable.Value!.Value.ToStandardFormattedString(1, cultureInfo: CultureInfo.InvariantCulture)}"; + string format(string acronym, DifficultyBindable bindable) => $"{acronym}{bindable.Value!.Value.ToStandardFormattedString(1)}"; } }