views:

16

answers:

1

Hello...I have a large text string number (20 characters, no decimals) that needs to be converted to a number. I tried Convert.ToInt64 but the value is too large. What is the best conversion method for a number this large? And, what is the actual max value for Convert.ToInt64()?

Thanks

+1  A: 

Int64 supports numbers from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807.

You can go larger using UInt64 (to 18,446,744,073,709,551,615).

If you need bigger than that, the best option is to use BigInteger, with BigInteger.TryParse instead of Convert.ToXXX. BigInteger supports arbitrarily large integer values, so the size can be as large as needed.

Reed Copsey
@Reed...That's great. Thanks! That's perfect....I'll do BigInteger.
MikeTWebb
@MikeTWebb: It's ideal for this - just realize it's .NET 4 (don't know if that matters for you). If you're .NET 2/3.5, you'll need a custom BigInteger class, like this one: http://www.codeproject.com/KB/cs/BigInteger_Library.aspx
Reed Copsey
@Reed....yeah, we are using .Net 3.5 so I need to implement that class. Sweet article. Thanks again
MikeTWebb