# Large number error. CS1021

Hello! I’m a Unity beginner and I’m making a clicker game. In my game, I need large numbers to be converted. I wrote this script, and it works. But if I want to convert 1.000.000.000.000.000.000 to 1qu (quintillion), I ran into a problem:

CS1021: Integral constant is too large.

I don’t know how to fix this. Help would be appreciated.

The same error happens with the float Money and the other costs.

Some information:
The variable CursorCost is a float. I’m using Unity 2021.1.16f1. Here is my code:

``````if (CursorCost < 1000000)
{
CursorText = CursorCost.ToString("F0");
}
if (CursorCost > 1000000 && CursorCost < 1000000000) // 1.000.000 to 1m
{
CursorText = (CursorCost / 1000000).ToString("F1") + ("m");
}
if (CursorCost > 1000000000 && CursorCost < 1000000000000) // 1.000.000.000 to 1b
{
CursorText = (CursorCost / 1000000000).ToString("F1") + ("b");
}
if (CursorCost > 1000000000000 && CursorCost < 1000000000000000) // 1.000.000.000.000 to 1t
{
CursorText = (CursorCost / 100000000000).ToString("F1") + ("t");
}
if (CursorCost > 1000000000000000 && CursorCost < 1000000000000000000) // 1.000.000.000.000.000 to 1qa
{
CursorText = (CursorCost / 100000000000000).ToString("F1") + ("qa");
}
if (CursorCost > 1000000000000000000 && CursorCost < 1000000000000000000000) // 1.000.000.000.000.000.000 to 1qu
{
CursorText = (CursorCost / 100000000000000000).ToString("F1") + ("qu");
}
``````

You really should read through the C# types section.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types#real-literals

You’re gonna need a different data type. Possibly multiple.

You could use a double. This is like a float, with twice as many bits, and according to Google you can get to a number that’s 308 digits long. However, depending on your needs, this might not be ideal. Floating point types are subject to floating point imprecision. Usually this just means “you can’t use == after doing math on floats because 1.999999998 is not 2.0”, but the size of the imprecision scales with the size of the number. I can’t find a simple answer to the question but when you’re looking at a 308 digit number this is almost certainly measured in whole numbers, not decimal points.

You may be better served by a class designed to hold arbitrarily large numbers, where if your number grows larger it decides to take more memory rather than breaking. You might want BigInteger. If you need decimals within that, I’d actually recommend having a float alongside that specifically for the decimals; that way you don’t ever have to worry about how big the precision might be at any given size.

As far as the code you’re writing now, I’m not certain that you’d be able to write 10000000000000000000000 into the code regardless, and you might need to parse such a large number from a string literal instead. However, there’s a much less repetitive way to go about this, which is to put it in a loop, something along the general lines of this:

``````private string GetString(BigInteger value) {
string[] suffixes = new string[]{"m", "b", "t", "qa", "qu"};
BigInteger currentDivider = 1000000;
if (CursorCost < currentDivider) return value.ToString();
foreach (var suffix in suffixes) {
if (value < currentDivider * 1000) return (value / currentDivider).ToString();
currentDivider *= 1000;
}
return "lots";
}
``````

wow, thanks!