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

@ -1,14 +1,14 @@
[
"0", // Hundert
"0,.##t", // Tausend
"0,,.##M", // Millionen
"0,,,.##Mr", // Milliarden
"0,,,,.##B", // Billionen
"0,,,,,.##Br", // Billiarden
"0,,,,,,.##T", // Trillionen
"0,,,,,,,.##Tr", // Trilliarden
"0,,,,,,,,.##Q", // Quadrillionen
"0,,,,,,,,,.##Qr", // Quadrilliarden
"0,,,,,,,,,,.##Qi", // Quintillionen
"0,,,,,,,,,,,.##Qir", // Quintilliarden
"0,.## t", // Tausend
"0,,.## M", // Millionen
"0,,,.## Mr", // Milliarden
"0,,,,.## B", // Billionen
"0,,,,,.## Br", // Billiarden
"0,,,,,,.## T", // Trillionen
"0,,,,,,,.## Tr", // Trilliarden
"0,,,,,,,,.## Q", // Quadrillionen
"0,,,,,,,,,.## Qr", // Quadrilliarden
"0,,,,,,,,,,.## Qi", // Quintillionen
"0,,,,,,,,,,,.## Qir", // Quintilliarden
]

View file

@ -1,14 +1,14 @@
[
"0", // hundreds
"0,.##K", // thousands
"0,,.##M", // millions
"0,,,.##B", // billions
"0,,,,.##T", // trillions
"0,,,,,.##Q", // quadrillions
"0,,,,,,.##Qi", // quintillions
"0,,,,,,,.##S", // sextillions
"0,,,,,,,,.##Sp", // septillions
"0,,,,,,,,,.##O", // octillions
"0,,,,,,,,,,.##N", // nonillions
"0,,,,,,,,,,,.##D", // decillions
"0,.## K", // thousands
"0,,.## M", // millions
"0,,,.## B", // billions
"0,,,,.## T", // trillions
"0,,,,,.## Q", // quadrillions
"0,,,,,,.## Qi", // quintillions
"0,,,,,,,.## S", // sextillions
"0,,,,,,,,.## Sp", // septillions
"0,,,,,,,,,.## O", // octillions
"0,,,,,,,,,,.## N", // nonillions
"0,,,,,,,,,,,.## D", // decillions
]

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