Money-system for decillionare game

I have been inspired a lot when playing games like “Egg Inc.” and “AdVenture Capitalist”. The idea seemed simple enough; earn a lot of money, by earning money. However, I really hit a wall and I don’t really know how to solve it. In these games you start with a couple of cents and then you start earning dollars, thousands of dollars, millions, billions, trillions etc. But the real thing with these games is that the amount of money reaches insane heights. Like decillions, and even double to that. But I can’t find a way to store numbers like that.

How, for example, would I track that the player has five duodecillion dollars, and even more so - how can I subtract three septillions from it?

Well, it depends on what range you want to cover. A lot cases can be handled by using a seperate quintillion(short scale) counter. So you could simply use two “long”(Int64) variables. Each can hold numbers up to

9 223 372 036 854 775 807

So when the lower counter reaches “1 quintillion” you simply subtract 1 quintillion from the lower counter and increase the upper counter by 1. This should be fairly easy to implement and simplifies the display of the number.

If you really want an unbounded number you have to use one of the BigInteger implementations. Those classes are quite slow to work with but you don’t have to handle anything yourself.

For example this BigInteger implementation. Though using two Int64 numbers would be much better for performance. You could reprensent numbers up to

9 223 372 036 854 775 807 223 372 036 854 775 807

with two long variables.