Text and numbers
How to Keep Leading Zeros in Excel and CSV (ZIP Codes, IDs)
To restore lost leading zeros, use =TEXT(A2,"00000") for a 5-digit code such as a US ZIP code, then paste the results as values. To stop Excel removing them in the first place, import the column as Text (Data, From Text/CSV, Transform Data, set the column type to Text) or format the cells as Text before you paste.
You open a customer file and the ZIP code 02134 now reads 2134. An employee ID 000457 reads 457. Nothing is wrong with the file: Excel simply treats anything that looks like a number as a number, and numbers have no leading zeros. This guide shows how to get them back and how to stop it from happening again.
Why Excel removes leading zeros
A cell in the default General format that contains 02134 is stored as the number 2134. Excel shows the number, not the typing. It happens with ZIP codes, product and barcode numbers, employee and account IDs, and phone numbers that start with 0.
The zeros are usually still in the CSV text file you were sent. They disappear when Excel opens the file and you save it again. So the safest habit is to keep the original file untouched and work on a copy.
Fix 1: add the zeros back with a formula
If every code should have the same length, rebuild it with TEXT. For a 5-digit ZIP code:
=TEXT(A2,"00000")
Use as many zeros as the final length. If some values may already be longer than the length you want, this version never cuts anything off:
=REPT("0",MAX(0,5-LEN(A2)))&A2
Fill the formula down, copy the results and use Paste Special, Values over the original column. The cells are now text, which is what you want. Excel may show a small green triangle ("number stored as text"); it is safe to ignore.
Fix 2: a number format, for display only
Select the column, press Ctrl+1, choose Custom and type 00000. The cell still holds the number 2134, but it displays as 02134. This is quick for viewing and printing. Because the underlying value is still a number, check how other tools see it: save a copy as CSV and open it in Notepad to see what was written.
Fix 3: stop it when you open a CSV
Double-clicking a .csv file makes Excel guess every column type, and the guess for 02134 is "number". Import it instead:
- Open a blank workbook and choose Data, Get Data, From File, From Text/CSV.
- Pick the file and click Transform Data.
- Click the header of the affected column, then Data Type, then Text. Repeat for every column that holds codes.
- Choose Close and Load.
In Google Sheets, use File, Import and untick "Convert text to numbers, dates, and formulas".
Fix 4: when typing or pasting
- Format the column as Text first (Home, Number format box, Text), then type or paste.
- Or type an apostrophe before the number:
'02134. The apostrophe is not stored in the cell.
Tip: format the whole column as Text before pasting data in. Formatting after the paste is too late, because the zeros are already gone.
The 15-digit limit
Excel keeps only 15 significant digits in a number. In a 16-digit ID, everything after the 15th digit silently becomes a zero, and Excel often displays the number as 1.23457E+15. Those digits cannot be recovered afterwards. Long identifiers must be text from the moment they are pasted or imported.
Warning: do not keep payment card numbers in a spreadsheet at all. They are sensitive, and a number-formatted column will also corrupt them.
Which fix for which data
| Data | Typical length | Best approach |
|---|---|---|
| US ZIP code | 5 digits | TEXT(A2,"00000"), or import as Text |
| ZIP+4 (02134-1234) | 10 with a hyphen | Already text, no problem |
| Barcodes (EAN-13, UPC) | 13 or 12 | Import as Text; never format as Number |
| Employee, order or account ID | Fixed | Import as Text, or TEXT with the right number of zeros |
| Phone numbers | Varies | Keep as text, see fixing phone numbers in Excel |
| Identifiers of 16 or more digits | 16+ | Text only, from the first moment |
Check for damage before you use the file
To count values that are shorter than a 5-digit code should be, which may have lost zeros:
=SUMPRODUCT((LEN(A2:A5000)>0)*(LEN(A2:A5000)<5))
A result above zero means some codes need a second look.
A whole file at once
DecodingPro reads each cell as it is stored and lists every change it makes, so a text value such as 02134 is never turned into a number, and nothing is changed without appearing in the log.
You start with 100 free credits. Every change is logged, and anything unclear is flagged, never guessed.
Fix a spreadsheetQuestions people ask
Why does Excel show 1.23E+11 instead of my number?
A long number in the General format is shown in scientific notation when the column is too narrow or the number has many digits. Up to 15 digits the value is intact: widen the column or format it as Number with no decimals. Beyond 15 digits the extra digits are already lost.
Can I get the zeros back after saving the file?
Only if you know the right length. If all codes should have 5 digits, a formula can rebuild them. If the lengths varied, the original values are gone and you need the source file.
Does Google Sheets have the same problem?
Yes. Format the column as Plain text (Format, Number, Plain text) before pasting, and untick the conversion option when importing a CSV.
Are the zeros lost in the CSV file itself?
Not unless you opened and re-saved it in Excel as numbers. Open the file in a plain text editor such as Notepad to see what is really inside.