mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Fix multiple issues with textbox content display
- Sometimes would display too many decimal digits due to floating point representation errors. - Placeholder would also look wrong if text was removed during a multiple (but determinate) selection.
This commit is contained in:
@ -19,6 +19,7 @@ using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
@ -219,7 +220,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
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 = findPrecision(decimalPrecision);
|
||||
int significantDigits = FormatUtils.FindPrecision(decimalPrecision);
|
||||
|
||||
TooltipText = floatValue.ToString($"N{significantDigits}");
|
||||
}
|
||||
@ -248,23 +249,5 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// <returns>The normalised decimal.</returns>
|
||||
private decimal normalise(decimal d, int sd)
|
||||
=> decimal.Parse(Math.Round(d, sd).ToString(string.Concat("0.", new string('#', sd)), CultureInfo.InvariantCulture), CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>
|
||||
/// Finds the number of digits after the decimal.
|
||||
/// </summary>
|
||||
/// <param name="d">The value to find the number of decimal digits for.</param>
|
||||
/// <returns>The number decimal digits.</returns>
|
||||
private int findPrecision(decimal d)
|
||||
{
|
||||
int precision = 0;
|
||||
|
||||
while (d != Math.Round(d))
|
||||
{
|
||||
d *= 10;
|
||||
precision++;
|
||||
}
|
||||
|
||||
return precision;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user