• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Trying to obtain zip codes beginning with 0

New Here ,
Apr 20, 2017 Apr 20, 2017

Copy link to clipboard

Copied

I'm trying to create an app that involves getting a zip code from the user, and then returns the corresponding latitude and longitude coordinates. I created an input text field for the user to enter a 5-digit zip code, and two text fields that display latitude/longitude. I'm pulling data from an xml file that contains nothing but zip codes and coordinates. So far, it runs perfectly for any zip codes not beginning in 0. But if the user were to enter a zip code beginning with one or more zeroes, such as "00987", the number returned is "987". Since that isn't a valid zip code, the latitude and longitude both return 0.

I could post my entire code but I'm not sure that's necessary, it seems more like I just don't understand how input text fields work, or I'm using the wrong method when parsing the user's input. I'm using a number variable for the zip code called myZip, and then using "myZip = parseFloat(zipCodeField.text);" to retrieve the number in the input text field.

Any help is really appreciated, I'm still quite new to Animate and coding so I'm not up to snuff on this kind of stuff yet.

Views

163

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 21, 2017 Apr 21, 2017

Why on Earth are you using parseFloat? ZIP codes aren't numbers, they're strings.

Votes

Translate

Translate
LEGEND ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

Why on Earth are you using parseFloat? ZIP codes aren't numbers, they're strings.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2017 Apr 21, 2017

Copy link to clipboard

Copied

LATEST

Well, I had been using a number variable for the zip codes, I see now I should've been using a string variable instead. Last time I did something like this it was with number variables but clearly that wasn't the right way to go about it here. Seems like it's working perfectly now, thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines