Why Leading Zeros Disappear
CSV stores everything as text. Spreadsheet apps then guess types when you open the file. Numeric-looking values like 02108 or 00045 get interpreted as numbers, and Excel drops the leading zeros because 2108 and 45 are the same numerically.
The CSV itself is fine. The reader stripped the zeros.
- US ZIP codes like 02108 become 2108.
- Employee IDs like 00045 become 45.
- Phone numbers like 0812345 lose the leading 0.
- Country codes and SKUs like 007A become 7A after conversion attempts.
The Two Root Causes
Fix the right cause. Do not blame the CSV.
| Cause | Where it hits |
|---|---|
| Spreadsheet auto-typing on open | Excel / Sheets after double-click |
| Numeric column type in destination | Databases and JSON typed schemas |
Step-by-Step: Keep Leading Zeros Safely
Depending on which side you control, use one or more of these fixes.
- Preview the CSV in the Online CSV Editor and confirm zeros are present in the source.
- If double-clicking Excel strips them, use Data > Get Data > From Text/CSV and set the ID column to Text during import.
- If you send CSV to others, keep the ID column as text and document that.
- For database loads, define the column as VARCHAR/TEXT (not INT).
- For JSON output, keep the value as a string rather than a number.
Excel Text column example
During Data > From Text/CSV import, click the ID column header and choose Text. Excel then leaves the leading zeros alone.
Python: read IDs as strings
Force pandas to keep the raw string for zero-prefixed columns.
import pandas as pd
df = pd.read_csv("employees.csv", dtype={"employee_id": str})
print(df["employee_id"].head())Node.js: keep as string
Do not cast to Number when parsing CSV rows.
const rows = parse(csv, { columns: true });
for (const row of rows) {
row.employee_id = String(row.employee_id);
}When You Cannot Change the Consumer
Sometimes a partner double-clicks the CSV and blames the file. Two workarounds help.
- Prefix values in Excel with a leading apostrophe (e.g., '02108) so Excel treats them as text. Note this changes the visible value if the recipient exports again.
- Deliver an .xlsx file instead of a CSV, where the column is explicitly typed as text.
Recommend an .xlsx delivery
Use the CSV to Excel Converter to produce an .xlsx with the correct types. Excel then respects the text type on open and stops silently editing zeros.
Real-World Examples
This bug wastes hours across every industry.
US ZIP codes
A mailing list loses 02108, 06010, 07030. Address matching fails until the ZIP column is treated as text.
Retail SKUs
Product SKUs like 000123 collide with 123 after auto-typing. Inventory sync breaks silently.
HR employee IDs
Zero-padded employee IDs are corrupted after a Save-As-CSV round trip. Fix: keep as text and re-export properly.
Common Mistakes
The reflex fixes often make things worse.
- Padding zeros back in with a formula on the fly and forgetting to remove it before export.
- Assuming the CSV is broken when the reader stripped the zeros.
- Reformatting the entire column as text after the values already lost zeros.
- Loading into a numeric database column and losing precision permanently.
Best Practices
Treat ID-like columns as text everywhere.
- Define ID/postal/phone columns as text in source systems.
- Import CSV with explicit column types.
- Deliver .xlsx when partners insist on double-click.
- Use string types in JSON and database schemas.
- Verify sample rows after every conversion step.
Why Use Convert CSV Online?
Convert CSV Online is free, browser-based, and needs no account for everyday conversions. Preview zero-prefixed columns in the Online CSV Editor, then use the CSV to Excel Converter to deliver a workbook where types are explicit. Client-side workflows run on Windows, macOS, and Linux browsers.
Ship an Excel file that keeps zeros
Convert your CSV to Excel with the correct column types and stop losing 0 prefixes at the recipient’s desk.
Conclusion
Leading zeros in CSV survive when you treat ID-like columns as text end to end. The CSV was fine; the reader made assumptions. Fix the reader, or ship a workbook that leaves no room for guessing.
FAQ
Why does Excel remove leading zeros from CSV?
Excel auto-detects the column as a number and drops the leading zeros because they do not change the numeric value. Set the column type to Text during import.
How do I keep leading zeros when importing CSV into Excel?
Use Data > Get Data > From File > From Text/CSV, then set the affected columns to Text before loading.
Does saving as CSV remove leading zeros?
Not by itself. The stripping usually happens when a spreadsheet app opens the CSV and re-types the column, then re-saves.
How can I ship data to non-technical partners without losing zeros?
Convert the CSV to an .xlsx workbook where the ID column is explicitly Text. Partners can open the workbook without triggering auto-typing.
How do I preserve leading zeros in a database?
Store ID-like columns as VARCHAR/TEXT rather than integer types.
How do I keep leading zeros in JSON?
Keep the value as a string, not a number. Numeric JSON types will drop leading zeros.
References
Convert your CSV in the browser
Preview, clean, and convert CSV files free with Convert CSV Online—no installation and no account required for everyday conversions.