Hello
I Want to make a clicker game, but, how does the big number, like in Adventure Capitalist,are managed?
Thanks
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.
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.
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 ?)
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?
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];
}
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