Convert String to Int
-
Hi, Please let me know how can i convert string x="10000000000" to int... i tried Convert.Int64 but im getting exception that number is too long or too short to store value in INt32..
I think the number is exceeding the limit of Int32 or Int64 try following code for successfully converting your string to number
If number >= Int32.MinValue And number <= Int32.MaxValue Then
newNumber = Convert.ToInt32(number)
Console.WriteLine("Successfully converted {0} to an Int32.", _
newNumber)
Else
Console.WriteLine("Unable to convert {0} to an Int32.", number)
End IfYou can use the same logic for Int64. HTH
Jinal Desai - LIVE Experience is mother of sage....
-
I think the number is exceeding the limit of Int32 or Int64 try following code for successfully converting your string to number
If number >= Int32.MinValue And number <= Int32.MaxValue Then
newNumber = Convert.ToInt32(number)
Console.WriteLine("Successfully converted {0} to an Int32.", _
newNumber)
Else
Console.WriteLine("Unable to convert {0} to an Int32.", number)
End IfYou can use the same logic for Int64. HTH
Jinal Desai - LIVE Experience is mother of sage....
-
pradeep455 wrote:
i tried Convert.Int64 but im getting exception that number is too long or too short to store value in INt32..
The error says number is too long or too short to store value in Int32.. So I think you are trying with Int32. HTH
Jinal Desai - LIVE Experience is mother of sage....
-
pradeep455 wrote:
i tried Convert.Int64 but im getting exception that number is too long or too short to store value in INt32..
The error says number is too long or too short to store value in Int32.. So I think you are trying with Int32. HTH
Jinal Desai - LIVE Experience is mother of sage....
-
even i tried with Convert.Int64 also..same error.. and im stroing in Int64 variable..still im getting the error..
-
"Was" not working or "is" not working? The above mentioned solution (int64 + parse) works fine. Tested:
string test = "10000000000";
System.Int64 int64 = Int64.Parse(test);
and it is totally ok.