Jen143 Jen143 - 1 month ago 4x
C# Question

How to Convert string("1.0000") to int

The string format data with mostly 4 decimal places needs to be converted into int.
I have tried this one but does not work and even directly using this Convert.ToInt16() but still did not worked:

Int32 result;
bool status = Int32.TryParse(v, out result);

Is there other ways to convert this?



You can convert it to Double first, and then convert to Int32

String s = "1.0000";
Double temp;

Boolean isOk = Double.TryParse(s, out temp);

Int32 value = isOk ? (Int32) temp : 0;