Big Numbers?

Hello
I Want to make a clicker game, but, how does the big number, like in Adventure Capitalist,are managed?
Thanks

1 Like

Can’t say for certain how other games handle it, there’s probably info available via google, but I would create my own value structure for BigNumbers, using scientific notation… something like

struct BigNumber {
  public float coefficient;
  public int exponent;

  public BigNumber (float c, int e) {
    this.coefficient= v;
    this.exponent = e;
  }

  public static BigNumber operator + ( BigNumber a, BigNumber b ) {
    return new BigNumber ( MATHS );
  }

}

then you just need to plug in all the MATHS for the various operators (add, subtract, multiply etc)

There are big number libraries out there that already roll everything for you.
https://bignumber.codeplex.com/

Furthermore, how big of numbers are we talking?

.Net’s built in ā€˜Decimal’ type has a sig value range of 28 decimal digits.

So you could hold a whole number value as large as:
10,000,000,000,000,000,000,000,000,000
That’s 10 octillion (short scale)

If you needed a couple fractional values (maybe 2, if you’re dealing with money), you just lose 2 of the upper limit sig values:
100,000,000,000,000,000,000,000,000.00
Still 100 septillion

Like I said, not sure how large of a value you’re looking for… but those appear pretty spanking big to me. And they’re moderately fast compared to most big number implementations.

1 Like

I Know there is a BigInt with 64 Bit in .NET, but i’m talking, how does in Adventure Capitalist, were you reach number like Tredecillion, the numbers are stored ?
Does the game Divide by 1000 the data everytime then change the notation?

EDIT
I think that’s it, you store a double number, when it goes over 1000 you divide it by 1000 then upgrade the notation, so for, let’s say, 234 333 111 111 (234 billion) in game you would have :
234.33 Billion
Internally you would have
NUM = 234.333111111
NOTATION = ā€œBillionā€

It’s mostly an array and some operator overloading

BigInt isn’t in the version of .Net that we Unity uses.

As for reaching numbers in the size you’re talking… when you have a Tredecillion… what does one thousand even mean anymore???

double will go all the way up to 10^308. The only thing is it only has about 16 or so significant decimal figures.

But when you’re up at 10^48 (tredecillion), would you really be adding on values 16 factors of 10 smaller?

I’ve managed this by chaining int64 together. You can get as high as you want without loosing any accuracy.

Or you could just use a double and forget about precision. Ever wonder why the genre has a habit of displaying numbers as 4.167 Quantillion Zillion instead of 12343027458973409852289800000000000000000000001? Its not just a screen space issue.

1 Like

I Don’t need really overprecision ^^
For Double, i can just use them like normal variable, i don’t need to implement something else ? (Like i just have a variable ā€œdouble cookieā€ then just manage it ?)

1 Like

Yup, nothing special at all. You could even use a regular float instead if you can keep within the limits.

Nice ! Now how do i display the big number in a short form ? (With the decillion & stuff)

Bump

If you’re going to go the route of using some multiple ints to store the values in. You should make it a struct, and then override the ā€˜ToString’ method, and format accordingly.

This is a custom type, you’ll have to do the formatting manually.

I Said earlier i’ll go with the double as they can handle the numbers needed, i just need to know how to print the value in form of a text, or, how to get the exponent of the double and be able to get a literal out of this, is there any c# lib that convert double to a ā€œreadableā€ form like this ? (Decillion,Tredecellion,…)

bump

No, there’s no built in way.

How about checking out google?

http://lmgtfy.com/?q=.net+format+number+to+words

I Checked google before coming here thanks, your google results are completly useless to me.

How are they useless?

The first 4 links are people doing the very thing you want in .Net and discussing how they accomplished it.

If their systems don’t go high enough… expand it, add the values you want to it.

Didn’t we mention this already? Its trivial, but a little tedious. Pseudo code follows.

string [] prefixes = new string [3] {"thousand", "million", "billion"}

public string ConvertBigNumberToString (float bigNumber){
    int noOfZeros = (int) Mathf.Log10(bigNumber);
    int prefixIndex = (int) (noOfZeros / 3);
    float displayNumber = bigNumber / (10 * 3 * prefixIndex);
    return displayNumber.ToString () + " " + prefixes[prefixIndex];
}
1 Like

Turns out I did.

The code in that link is less psuedoish then the code I’ve just written above. I also go through a whole bunch of other considerations that apply when working with big numbers.

Ah nice
But for Displaynumber, the formula seems wrong
Here is some examples of what i want

123 000 000 000
To be displayed as 123 Billions

123 123 000 000
To be displayed as 123.12 Billions

1 123 000 000 000
To be displayed as 1.12 Trillions