I am trying to make a clicker game in un. Currently I am using doubles as a way to show large numbers. However when I get to any numbers above a trillion, it goes to -1354 trillion or something like that. The code shown bellow is code to fill in large numbers as "___ Million" or "____ Billion" but once it gets past 999 Billion is shows "-1354 Trillion". It continues to act like a trillion dollars, as you can buy items with apparently negative money, but the display is all wrong.
I have tried changing the double to int, long, and float and all of them result in the same issue. I have also tried even larger numbers but they don't even work in the system. It seems like 999 Billion is the limit before it turns all hell loose.
public static string largeWholeNumbers(double number)
{
int numOfZeros = (number.ToString()).Length; //Gets Length of number
int zeroSets = (int)Mathf.Floor(numOfZeros / 3.001f); //Divides it by a little over 3 and floors it
double numDisplay = number/(power(10, ((2 *zeroSets) + (zeroSets - 1)))); //Get the thing infront of the illion (IE 134, 6 million)
//Defines
string numberName = "";
int hugeNumberSet = 0;
int hugeNumberStart = 0;
int hugeNumberStartIndex = 0;
int hugeNumberEnd = 0;
if (zeroSets < 11)
{
zeroSets -= 2;
numberName = numberEndings.wholeNumEndings[zeroSets];
}
if (zeroSets > 10)
{
hugeNumberSet = (int)Mathf.Floor((zeroSets - 1)/10); //Divides it by 10 to get 10, 20, 30 etc
hugeNumberEnd = hugeNumberSet - 1;
hugeNumberStart = zeroSets - (hugeNumberSet * 10); //Example zeroSet = 12, this = 2
hugeNumberStartIndex = hugeNumberStart - 1;
if (hugeNumberStart < 1)
{
numberName = numberEndings.endNumEndings[hugeNumberEnd];
}
if (hugeNumberStart >= 1)
{
numberName = numberEndings.endNumEndings[hugeNumberEnd] + numberEndings.beginNumEndings[hugeNumberStartIndex];
}
}
return numDisplay.ToString() + " " + numberName;
}
Expected results would be to show the number in the interface as "1 Trillion", however it shows it as "-1354 Trillion".