leading zeros help!

When I input zip codes, and 0 is the first number in the cell, numbers automatically deletes the 0. For example if the zip code is 07733, when i hit enter or move to the next cell is becomes, 7733. How do I change this setting?

Mac OS X (10.4.11)

Posted on Jul 14, 2008 8:00 PM

Reply
16 replies

Jul 16, 2008 6:32 PM in response to witchycb

It should perhaps be noted that neither of the two previous suggestions will recover leading zeros from a cell set to automatic (or a number) cell format once the value has been set by moving out of it.

It is sometimes said that the cell format is just the display format, but in this respect that is not completely true. The cell format actually determines how the value will be interpreted after entry & stored in the document: if interpreted as a number, leading zeros will be lost forever; if as a partial date_time, additional value information will be added. In neither case will changing the format afterwards to text reverse this & restore the originally entered form.

For this reason, the best "tip" is to preset the cell format to text before entering data. When it is too late for that, a formula may sometimes help, like one that detects zip codes less than 5 characters long & creates a text copy in a new column with the leading zero(s) restored. One such formula is =RIGHT("00000" & zipnumbercell,5), assuming that zipnumbercell contains only the 5 digit zip code without leading zeros. The nine digit extended form would require a more complex formula if it were mixed with 5 digit entries.

Jul 17, 2008 3:50 AM in response to R C-R

Mainly because I am accustomed to this kind of format since the first day I used AppleWorks. I used the NO-BREAK SPACE or the LATIN CAPITAL LETTER O WITH STROKE.
I was required because several uses of these values dropped the leading zeroes and in my geographic area, postal codes are 06xyz.

In Numbers, it seems that the text format is more robust but I never tested every features so, I play safety.

I wrote too fast. The ZERO WIDTH NO-BREAK SPACE must not be inserted at end but in the body of the number. For postal code I insert it between 06 and 220.
As far as I know, when the leading zeroes are required, it's not to use the value in arithmetic operations so the extra character has no odd effect.

When I have to apply calculations upon string lengths, I use the LATIN CAPITAL LETTER O WITH STROKE and all works perfectly.

It's the way I work, nobody is forced to work the same 😉

Yvan KOENIG (from FRANCE jeudi 17 juillet 2008 12:49:31)

Jul 17, 2008 4:42 AM in response to KOENIG Yvan

I'm not sure why you would need to add any character to a postal code that is already alphanumeric -- are you saying that Numbers (or AppleWorks?) dropped leading zeros in such things?

FWIW, in the U.S. we now have a nine digit extended zip code system (called "zip + 4") that specifies postal delivery areas more completely within the 5-digit delivery area. Because the format is xxxxx-xxxx (5 digits, a dash, & 4 more digits), using this format would avoid the problem in Numbers, assuming one knows the complete zip code, since the "-" in the value prevents it from being interpreted as a number. It even works (in a U.S. localized system) if one enters just the 5 digit zip code & a trailing dash.

Jul 17, 2008 5:21 AM in response to R C-R

Everybody is not living in the USA.

In France postal code is made of 5 digits.
AppleWorks, Numbers and other tools drop the leading zero (I often receive with a delay of several days letters with 6220 VALLAURIS in lieu of 06220 VALLAURIS).

Postal service ask us to use a space between the code and the city name.

if we use =zip & " " & city or =concatenate(zip," ",city) the leading zero is dropped
Of course I know the formula:
=RIGHT("00"&zip&" "&C,LEN(zip&" "&city)+5-LEN(zip))

But, as I often wrote, I'm lazy.

Yvan KOENIG (from FRANCE jeudi 17 juillet 2008 14:21:08)

Jul 17, 2008 8:17 AM in response to KOENIG Yvan

KOENIG Yvan wrote:
Everybody is not living in the USA.


No, but pretty much everyone that calls them "zip codes" is referring to the U.S. postal codes, & that is what I assumed the O.P. meant.

Anyway, when you described the French postal code format as "06xyz" I thought you meant that was the alphanumeric (both letters & numbers) form used in many countries. Obviously, that kind of format doesn't present a problem of misinterpretation as a number.

Jul 17, 2008 8:34 AM in response to R C-R

As a French user I know what is a "code postal" in France. I am unable to make a difference between U.S. "zip code" and U.S. "postal code".

As an old mathematician, I uses x,y,z as digits place holders.
x may be 0 thru 9
y may be 0 thru 9
z may be 0 thru 9.

French postal codes are made of to digits for the department then three digits for the city.
The result is a five digits code. No letter embedded.

Yvan KOENIG (from FRANCE jeudi 17 juillet 2008 17:32:26)

Jul 17, 2008 10:20 AM in response to KOENIG Yvan

FWIW, the "zip" in the U.S. postal code system stands for Zone Improvement Plan. "ZIP Code" was a registered service name used by the U.S. Postal Service to promote its use to the public.

BTW, I'm an old mathematician too, but in the U.S. I was taught that the convention for the use of "x, y, & z" is to indicate unique or primary variables, whereas "n" indicates a number. The conventions of computer nomenclature more or less follow that but there are enough variations that I wasn't sure what you meant. Now I know. 🙂

Oct 14, 2008 1:37 AM in response to Sunil Joshi1

Ok, never mind. I figured it out.
For future readers - the way to use the formula =RIGHT("00000" & zip numbercell,5) is to create a new column and use the formula in that column with the zip numbercell being the cell of the original zip with 4 characters.

rant
Using spreadsheets for managing addresses is a very common thing. I cannot understand why a modern spreadsheet product, after at least 30 years of development, would still not have a pre-formatting for zipcodes. Microsoft excel has it, but Numbers doesn't! Seems a bit backward for a company that seems to be sensitive to customer needs. I wasted a good 4 hours trying to figure this out and am appreciative of the user community's help. But this SHOULD NOT BE NECESSARY!
end-of-rant

Oct 14, 2008 2:21 AM in response to Sunil Joshi1

Hello

Who told you that Numbers is the result of 30 years of development?

It's a baby (version 1.0.2)
Its designers perfectly kno what is done by Excel.
They are certainly not trying to build a clone of this one.
They defined a target range of customers and what you requires is not a feature needed by the defined target. No less, no more. Its a well known:

+-+-+-+-+-+-+-+-+

Apple Human Interface Guidelines:
Apply the 80 Percent Solution
During the design process, if you discover problems with your product design, you might consider applying the 80 percent solution‚ that is, designing your software to meet the needs of at least 80 percent of your users. This type of design typically favors simpler, more elegant approaches to problems.
If you try to design for the 20 percent of your target audience who are power users, your design may not be usable by the other 80 percent of users. Even though that smaller group of power users is likely to have good ideas for features, the majority of your user base may not think in the same way. Involving a broad range of users in your design process can help you find the 80 percent solution.

-+-+-+-+-+-+-+-

Yvan KOENIG (from FRANCE mardi 14 octobre 2008 11:20:40)

Jan 11, 2009 4:57 PM in response to witchycb

This "leading zero" issue might be the deal-breaker for me. I have large CSV files I have to import every day into a spreadsheet. In Excel, I could tell it to format a column as text before I imported the data. Since one column of data is long serial numbers sometimes having leading zeros, this is a must.

In Numbers, this seems to be impossible. Once you open the file, the leading zeros are gone, never to return. Is there some trick I'm missing to format the column before importing a file?

Jan 12, 2009 6:20 AM in response to Blazeland

You can't define the format of a file which doesn't exists.

As long as the CSV is not imported, there is no Numbers document to format.

You may use this script


--[SCRIPT zeroHead.app]

(*
Enregistrer le script en tant qu'Application ou Progiciel : zeroHead.app
déplacer l'application créée dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
Copier les nombres à formater dans le presse-papiers
Placez le curseur où ça vous chante dans Numbers
menu Scripts > zeroHead
Le script collera les nombres formatés selon le masque zeroHead
+++++++
Save the script as an Application or an Application Bundle: zeroHead.app
Move the newly created application into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
Copy the numbers to format in the clipboard
Put the cursor where you wish in Numbers
menu Scripts > zeroHead
The script will paste the numbers after applying the mask.
Yvan KOENIG le 7 mars 2008
*)
property listeLignes : {}
property listeTempAvant : {}
property listeTempApres : {}
property listeApres : {}
property nbDigits : 5
property zeroes : ""
property myZero : "O" (* upper O, you may use Ø = slashedZero *)
property theApp : "Numbers"
property menuFenetre : 10
property premierNom : 6
property nomDuDocActif : ""
--=============
on run
tell application "System Events" to if not (UI elements enabled) then set (UI elements enabled) to true (*
Active le GUI scripting
• Enable GUI scripting *)
if zeroes is "" then
repeat nbDigits times
set zeroes to zeroes & myZero
end repeat
end if

my nettoie()
my controleVersion()
set nomDuDocActif to my getFrontDoc()
if nomDuDocActif = "" then return

try
set textdatas to (the clipboard) as Unicode text
on error (*
The clipboard was empty *)
return
end try


set my listeLignes to paragraphs of textdatas
try
if textdatas contains tab then (*
plusieurs colonnes *)
repeat with ligne in my listeLignes
set my listeTempAvant to my decoupe(ligne as text, tab)
set my listeTempApres to {}
repeat with nn in my listeTempAvant
copy my applyTheMask(nn) to end of my listeTempApres
end repeat
copy my recolle(my listeTempApres, tab) to end of my listeApres
end repeat
else (*
une seule colonne *)
repeat with nn in my listeLignes
copy my applyTheMask(nn) to end of my listeApres
end repeat
end if
set the clipboard to my recolle(my listeApres, return)
my pasteIt()
my nettoie()
end try
end run
--=============
on pasteIt()
tell application theApp to activate
tell application "System Events" to tell (first process whose title is theApp)
click menu item nomDuDocActif of menu 1 of menu bar item menuFenetre of menu bar 1
keystroke "v" using {command down}
end tell
end pasteIt
--=============
on applyTheMask(n)
copy n as text to n
if n is not "" then
if n contains "0" then set n to my recolle(my decoupe(n, "0"), myZero) (* replaces zero by myZero *)
set n to text -nbDigits thru -1 of (zeroes & n)
end if
return n as text
end applyTheMask
--=============
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=============
on recolle(l, d)
local t
set AppleScript's text item delimiters to d
set t to l as text
set AppleScript's text item delimiters to ""
return t
end recolle
--=============
on nettoie()
set my listeLignes to {}
set my listeTempAvant to {}
set my listeTempApres to {}
set my listeApres to {}
set nomDuDocActif to ""
end nettoie
--=============
(*
Get the name of the active document
*)
on getFrontDoc()
local nw, mm
tell application theApp to activate
tell application "System Events" to tell (first process whose title is theApp)
set nw to name of every menu item of menu 1 of menu bar item menuFenetre of menu bar 1
if (count of nw) < premierNom then
set mm to ""
else
repeat with i from premierNom to count of nw
set mm to item i of nw
if (value of attribute "AXMenuItemMarkChar" of menu item mm of menu 1 of menu bar item menuFenetre of menu bar 1) is not in {"", "•"} then exit repeat
end repeat
end if -- (count of nw)…
end tell
return mm
end getFrontDoc
--=============
on controleVersion()
local v
try
set v to version of application theApp
set menuFenetre to 10 (* index of the Windows menu *)
set premierNom to 6 (* index of the first docName in the list of menu names
The list contains one more item than the displayed menu *)
on error (*
• We are here if Numbers ignores the instruction get version *)
tell application "System Events" to set v to get version of (get (application file of (get first process whose title is theApp)))
if v starts with "1" then
set menuFenetre to 10
set premierNom to 6
else (* ready for a Numbers v2 ignoring AppleScript *)
set menuFenetre to 10
set premierNom to 6
end if
end try
end controleVersion
--=============
--[/SCRIPT]


It will replace every zero or missing zero by the upper O (or by slashedZero Ø)
so the ZIP will remain fixed.

Yvan KOENIG (from FRANCE lundi 12 janvier 2009 15:19:20)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

leading zeros help!

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.