Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I need to convert a string of length equals to 24 to an integer.

Convert.ToInt32()isn't working for me, its throwing the following error:
Value was either too large or too small for an Int32.


I tried Convert.ToInt64() and it showed the same error.

I need this conversion for numerical comparisons. The conversion doesn't need to be to an integer type.

Any idea how to resolve this issue?

Thank you
Posted
Updated 1-Oct-10 2:44am
v3

You could try something like the C# BigInteger Class[^].
 
Share this answer
 
Is this what your referring to:

C#
int @int = int.Parse("123456789009876543211234");

VB.NET
Dim int As Integer = Integer.Parse("123456789009876543211234")
 
Share this answer
 
Comments
deadwood88 1-Oct-10 9:21am    
This gives the same error: Value was either too large or too small for an Int32
Convert it to a double

string test = "0123456789012345678901234567890";

double dTest = Convert.ToDouble(test);


this will produce 1.2345678901234568E+29 precision could be a problem however...
 
Share this answer
 
Comments
deadwood88 1-Oct-10 9:34am    
Yes, there is a problem with precision here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900