## C# how can I store my integer and do math with it if it's too large for Int32

c# integer class

c# tutorial

c# numbers

getting started with c#

c# math

c# integer division

convert string to int c#

**Closed**. This question needs to be more focused. It is not currently accepting answers.

Try this:

long nid = Convert.ToInt64(itemId);

The number that you deal with overflows Int32 range. But you can use long (or Int64, it's the same thing) and continue doing your math calculations.

**Numbers in C#,** Make that the current directory and run the following command: You've seen one of the fundamental math operations with integers. Comments are any text you want to keep in your source code but not execute as code. The C# integer type differs from mathematical integers in one other way: the int type has minimum and maximum limits. Add this code to your Main method to see those limits: int max = int.MaxValue; int min = int.MinValue; Console.WriteLine($"The range of integers is {min} to {max}");

You can use long instead of int or you can use BigInteger (known from Java): https://archive.codeplex.com/?p=biginteger

**Professional C# 4.0 and .NET 4,** However, the expression myInteger + myUnsignedInt is really just an intuitive Do not worry if mathematics is not your strong point — we will keep the vector Use the Math.DivRem method to compute both integer division and remainder results. Floating-point remainder. For the float and double operands, the result of x % y for the finite x and y is the value z such that. The sign of z, if non-zero, is the same as the sign of x.

the problem is that your number is greater than a Int32 could store.

you must use `Int64`

. and use `Int64`

instead of `int`

Int64 nid = Convert.ToInt64(itemId);

note that `Int64`

and `long`

is the same.

Another option is to use an `unsigned Int32`

. then the Int32 will not store negative numbers, and then have enough space to store biggers numbers

**Numeric Variable Types,** The amount of memory used to store a variable is based on its data type. Listing 3.4 is a Recall that an integer is basically any numeric value that does not include a decimal or a fractional value. Using bits and the binary math system, you can store numbers in multiple bits. Save To My Account Close. The default value of each integral type is zero, 0. Each of the integral types has the MinValue and MaxValue constants that provide the minimum and maximum value of that type. Use the System.Numerics.BigInteger structure to represent a signed integer with no upper or lower bounds. Integer literals. Integer literals can be.

**.NET 4 Wrox PDF Bundle: Professional ASP.NET 4, Professional C# 4, ,** NET 4, Professional C# 4, VB 2010 Programmer's Ref, WPF Programmer's Ref, However, the expression myInteger + myUnsignedInt is really just an intuitive Do not worry if mathematics is not your strong point — we will keep the vector Use a number line of positive and negative numbers and zero. Put a dot above the first addend. Think of the number’s sign as a direction on the number line: go right for positive numbers and left for negative numbers. If you are adding -8 and -6, place a dot above -8 on the number line. Since -6 is negative, move six spaces to the left. End

**Beginning Visual Basic 2005 Express Edition: From Novice to ,** If you try to store a Double value into an Integer, Visual Basic will quite After mentioning earlier that I like to be explicit in my code, it might seem In simple math like this VB will do it for me without me having to CType it, but In fact many languages (C# and Java, for example) force you to do an explicit cast of data types. Returns an integer that indicates the sign of a 32-bit signed integer. Sign(Int64) Returns an integer that indicates the sign of a 64-bit signed integer. Sign(SByte) Returns an integer that indicates the sign of an 8-bit signed integer. Sign(Single) Returns an integer that indicates the sign of a single-precision floating-point number. Sin(Double)

**Professional C# 5.0 and .NET 4.5.1,** of math, matrices can be added together and multiplied, just like numbers. + b); By overloading the operators, you can tell the compiler what + and * do when used everything: what methods are available to call, what fields to store with each suppose that the compiler processes the following lines of code: int myInteger To understand how we can store and manipulate data in C# let's take an example of storing 2 integer numbers (integer numbers are the whole numbers like 1,2,3 and 1000 as we will know later). The computer and the compiler of C# are responsible for allocating memory locations for program's data.

##### Comments

- What about converting to int.64, You need a long rather than int.
`long nid = 2293128329L;`

if`itemId`

is of type`string`

you can parse it:`long nid = long.Parse(itemId);`

. Finally, you can try converting:`long nid = Convert.ToInt64(itemId);`

- fixed my issue, thank you.
- There is already an identical answer by @Andrei. No need to explain something so simple twice.