This is just a quick post to point out that ZIP codes should never be stored or represented as integers. ZIP codes should always be stored and represented as strings. Take the ZIP code 07755 (Oakhurst, NJ), for example. Any reasonable parsing algorithm will correct read in 07755, but 07755 will be immediately converted to 7755 as leading zeros mean nothing in the context of integers. The problem doesn’t become apparent until it becomes time to output the ZIP code (for example, in a KML file). 7755 is not a valid ZIP code.
A common place where this problem pops up is in web apps where user ZIP codes are stored. In Django, for example, you may be tempted to add the following field to a model:
zip = models.IntegerField(max_length=5) |
While this will certainly work, if you ever need to display user ZIP codes (e.g., to let a user view their current address), leading zeros won’t be displayed. Instead, the correct way to represent a ZIP code would be:
zip = models.CharField(max_length=5) |
Now, leading zeros won’t get cut off.