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:
Bartłomiej Dach
2021-11-12 23:07:24 +01:00
parent e55e2a1697
commit d567d2be97
3 changed files with 28 additions and 21 deletions

View File

@ -31,5 +31,23 @@ namespace osu.Game.Utils
/// </summary>
/// <param name="rank">The rank/position to be formatted.</param>
public static string FormatRank(this int rank) => rank.ToMetric(decimals: rank < 100_000 ? 1 : 0);
/// <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>
public static int FindPrecision(decimal d)
{
int precision = 0;
while (d != Math.Round(d))
{
d *= 10;
precision++;
}
return precision;
}
}
}