cache exponent values for number formats

This commit is contained in:
Ellpeck 2020-06-25 15:32:11 +02:00
parent bb0fd54713
commit f03b14d07b
3 changed files with 24 additions and 23 deletions

View file

@ -23,6 +23,7 @@ namespace TouchyTickets {
public class Ui {
public static readonly UniformTextureAtlas Texture = new UniformTextureAtlas(MlemGame.LoadContent<Texture2D>("Textures/Ui"), 16, 16);
private static readonly BigInteger[] ExpoNums = Enumerable.Range(0, Localization.NumberFormat.Count).Select(i => BigInteger.Pow(1000, i + 1)).ToArray();
private readonly UiSystem uiSystem;
private readonly Element[] swipeRelations;
private Element currentUi;
@ -602,7 +603,7 @@ namespace TouchyTickets {
private static string PrettyPrintNumber(BigInteger number) {
for (var i = 0; i < Localization.NumberFormat.Count; i++) {
if (number < BigInteger.Pow(1000, i + 1))
if (number < ExpoNums[i])
return number.ToString(Localization.NumberFormat[i]);
}
// if the number is too large, just return the highest possible