I am trying to convert a _string[1] to double and _string[2] to Int
this string array is generated dynamically.
string value can be empty or 1.1 or 1 or .1 how can i handle this.
i trying doing like this.
string locale;
locale = System.Web.HttpContext.Current.Request.UserLanguages[0];
CultureInfo culture;
culture = new CultureInfo(locale);
double cValue = Double.Parse(_string[1], culture.NumberFormat)
int sValue = Int32.Parse(_string[2], culture.NumberFormat)
this sometime give me invalid input when there is empty string or decimal string
For the double you could use a ternary operator like this
double d = Double.TryParse(_string[1], out d) ? Convert.ToDouble(_string[1]) : 0;
In order to make it safe you could either use a try-catch or the Double.TryParse method which is a better option.
If you want to display this, you will get 0 as an output. You can turn that into a 0.00 with the following line
string output = (String.Format("{0:0.00}", cValue));