Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8131063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:57:51+00:00 2026-06-06T08:57:51+00:00

I have an Asp.net text box that is being auto populated by javascript using

  • 0

I have an Asp.net text box that is being auto populated by javascript using Google Maps Api.
The text in the textbox can show any amount of miles from 40.2 – 1,634 mi ect.

I need to take the text from the text box and put it into an int to be stored in the DB.

So really I need a couple things to happen. The text always shows as “40.2 mi” (without the quotes) and what I need is just a round number. or Int. like “40” or “1634”.

So I can store this in my DB table. I’ve tried Substring and Math.Round. But I keep getting exceptions. My most recent attempt is this:

        string miles = txtEstDistance.Text;
        miles.Substring(0, miles.IndexOf('.') > 0 ? miles.IndexOf('.') : miles.Length);

        int oDistanceMiles = Convert.ToInt32(miles);

And the exception I’m getting is:”Input string was not in a correct format.” for this line of code:

int oDistanceMiles = Convert.ToInt32(miles);

I’m lost. .Net 4.0 C#

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:57:53+00:00Added an answer on June 6, 2026 at 8:57 am

    What if you get rid of the ” mi” first, and treat the rest as a float? Then you can use the Math.Round to round to a whole number and convert that to an int.

    If I’m right, the NumberStyles.Float enum will automatically clean up leading or trailing white space. Of course, you can also use string.Trim()

    var miles = txtEstDistance.Text;
    
    miles = miles.Substring(0, miles.IndexOf("mi"));
    
    float tmpdistance;
    var success = float.TryParse(miles, NumberStyles.Float, CultureInfo.InvariantCulture, out tmpdistance);
    
    if (success)
    {
        var distance = Convert.ToInt32(Math.Round(tmpdistance, 0));
    
        // or
    
        distance = (int) Math.Round(tmpdistance, 0);
    }
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asp.net TextBox with ontextchanged event this is search text box in my
I have an asp.net web page with a simple search text box that returns
I have a ASP.Net web form that contains both text box fields and hidden
I have an asp.net textbox that is disabled: <asp:TextBox ID=txtEmpName runat=server Enabled=false></asp:TextBox> Using jQuery,
I have an ASP.NET MVC Partial View that contains a Html.TextBox that is configured
I have a asp.net web content from that have a asp.net textbox and I
the problem is that I do have an ASP.NET TextBox in a FormView with
I have a ASP.NET web page that contains many textboxes. Each textbox has a
I have information entered into a text box on an ASP.net 3.5 page. when
I have an asp.net TextBox in which I want to check if the text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.