I am currently working on a project where I have an Asp.net text box that is being automatically populated by JavaScript using the Google Maps API. The text in the textbox can display varying distances ranging from 40.2 miles to 1,634 miles and so on.
My main goal is to extract the numerical value from the text box and convert it into an integer for storage in the database.
The challenge lies in ensuring that the extracted number is always in a rounded format, such as "40" or "1634", without any decimal points or extra characters.
I have attempted methods like Substring and Math.Round, but unfortunately, I keep encountering exceptions. Here is my latest try:
string miles = txtEstDistance.Text;
miles.Substring(0, miles.IndexOf('.') > 0 ? miles.IndexOf('.') : miles.Length);
int oDistanceMiles = Convert.ToInt32(miles);
However, I am consistently getting the exception: "Input string was not in a correct format." specifically for this line of code:
int oDistanceMiles = Convert.ToInt32(miles);
I am feeling quite lost at this point. Using .Net 4.0 with C# programming language.