Hi all I am having a numeric digit with 20 characters as follows 34432523434234423434
, I tried this converting using long,UInt64
but still I am getting an exception Value was either too large or too small
so can some one help me out how can I convert this value

- 351
- 7
- 25
-
Try `Decimal.Parse`, the the `decimal` datatype is suitable for your needs. – Steve Guidi Apr 09 '14 at 15:25
-
Conver it to Big Integer `BigInteger i = new BigInteger(); i = BigInteger.Parse("34432523434234423434");` – HackerMan Apr 09 '14 at 15:28
2 Answers
Your value is actually 65 bits long, so doesn't matter HOW you change its type, it will not fit into a 64bit variable.
2**64 = 18446744073709551616
your value = 34432523434234423434

- 356,200
- 43
- 426
- 500
-
I tried using biginteger as follows but still I am unable to acheive `BigInteger assignedFromLong = (BigInteger)34432523434234423434;` – Learner Apr 09 '14 at 15:27
Big integers aren't actually limited to 20 digits, they're limited to the numbers that can be expressed in 64 bits (for example, the number 99,999,999,999,999,999,999 is not a valid big integer despite it being 20 digits long).
The reason you have this limitation is that native format integers can be manipulated relatively fast by the underlying hardware whereas textual versions of a number (tend to) need to be processed one digit at a time.
If you want a number larger than the largest 64-bit unsigned integer 18,446,744,073,709,551,615 then you will need to store it as a string (or other textual field) and hope that you don't need to do much mathematical manipulation on it.
Alternatively, you can look into floating point numbers which have a larger range but less precision, or decimal numbers which should be able to give you 65 digits for an integral value, with decimal(65,0) as the column type.

- 1,319
- 7
- 17
-
No varchar in C#. Generally a good answer, apart from the varchar stuff. Also why stringify a value you can store in a decimal? – Liam Apr 09 '14 at 15:27