Sub topic 8
Leading zeros, dates and other type pitfalls
This chapter assumes you can run File > Import, know where the "Convert text to numbers, dates, and formulas" option sits, and know that the spreadsheet locale is set under File > Settings. It also assumes you can write basic formulas such as TRIM and TEXT. The chapter covers how a type error happens, how to spot one, and how to fix it either before the import or afterwards.
Why types go wrong
A CSV file has no types. Every field is text, and 00501, 2026-11-28 and 1E5 look the same to the file. Sheets guesses the type of each field as it loads it. When "Convert text to numbers, dates, and formulas" is on, Sheets tries to read each field as a number, date, time, boolean or formula. The guess is lossy: once 00501 becomes the number 501, the zeros are gone and cannot be recovered from the cell.
Three things drive the guess:
- The conversion checkbox in the import dialog.
- The spreadsheet locale, which decides which date order, decimal mark and thousands separator count as valid.
- The cell's existing number format, which matters when you replace or append into a range that was already formatted.
The safest habit is to decide per file whether you want guessing at all. If a file contains identifiers, turn conversion off. If it contains measurements and dates you will calculate with, leave it on and check the result.
Leading zeros
Identifiers such as ZIP codes, product SKUs, employee numbers and account codes often start with zeros. They are labels, not quantities, so they should stay text.
Prevent the loss
- In File > Import, set "Convert text to numbers, dates, and formulas" to off.
- Import. Every field arrives as text, so
00501stays00501. - Convert only the columns that need to be numbers, using VALUE or a number format.
If you can't turn conversion off, for example because other columns need to be numeric, import first and then repair the identifier column.
Repair after the fact
If the original width is fixed, such as five digits for a US ZIP code, TEXT can pad the number back:
=TEXT(A2, "00000")The result is text, so copy the column and use Edit > Paste special > Values only to replace the formulas with fixed values.
The repair works only when every code has the same length. A column that mixes 4-digit and 6-digit codes cannot be restored by guessing. In that case re-import from the source file with conversion off.
The alternative is a custom number format. Select the cells, then choose Format > Number > Custom number format and enter 00000. The cell still holds the number 501 and only displays 00501. Anything that reads the underlying value, such as a lookup against text codes, a CSV export from another tool, or a JOIN in a database, sees 501. Use the TEXT approach when the value must be text.
Phone numbers and plus signs
A phone number like +441632960000 is read as the number 441632960000 and the plus sign disappears. Numbers beginning with 0 lose that zero in the same way. Treat phone numbers as identifiers and import them as text.
Dates
Dates are the most common source of silent errors, because a wrong date is still a valid date.
Sheets stores a date as a serial number, the count of days since December 30, 1899. A date cell is a number with a date format applied. When a field is recognised as a date, Sheets converts it to this number. When it is not recognised, the field stays text.
Locale decides the order
The string 03/04/2026 is March 4 in a US locale and April 3 in a UK locale. Sheets uses the spreadsheet's locale (File > Settings > Locale) to decide, not the locale of the person who made the file.
The same file produces two different results in two spreadsheets:
| Field | Locale: United States | Locale: United Kingdom |
|---|---|---|
| `03/04/2026` | March 4, 2026 | April 3, 2026 |
| `28/11/2026` | Text, because there is no month 28 | November 28, 2026 |
The second row is the dangerous part of a mixed column. Days 1 to 12 convert to wrong but valid dates, and days 13 to 31 stay as text. You end up with a column where some cells are dates and others are not, and a quick glance shows nothing wrong.
Two ways to avoid the problem:
- Set the spreadsheet locale to match the file's origin before you import. Do this first, because changing the locale afterwards does not reinterpret dates that were already converted.
- Ask the source system for ISO 8601 dates (
2026-11-28). The year-first form is read the same way in all locales.
Repairing text dates
If a date column stayed as text, DATEVALUE converts a string that the current locale recognises:
=DATEVALUE(A2)If the text uses an order your locale does not accept, build the date from its parts. For 28/11/2026 in a US-locale sheet:
=DATE(RIGHT(A2, 4), MID(A2, 4, 2), LEFT(A2, 2))This works only for a fixed layout with two-digit day and month. For variable layouts, use SPLIT to separate the parts first.
If the dates were converted wrongly (for example, March 4 where April 3 was meant), the day and month have been swapped inside valid dates, and no formula can tell which cells are wrong. Fix the locale and re-import.
Times and two-digit years
A field such as 14:30 becomes a time, stored as a fraction of a day. A field like 1-2 may become January 2 of the current year, so check short fields that you meant as ranges or codes. Two-digit years such as 26 are interpreted by Sheets using a sliding window, so avoid them when the file has any alternative.
Other type pitfalls
Long numbers lose digits
Sheets keeps 15 significant digits. A 16-digit card number, tracking number or database ID that is imported as a number has its extra digits replaced by zeros. The loss happens at import and cannot be reversed. These values must be imported as text, which means turning conversion off for that file.
Wide numbers may also show in scientific notation, such as 1.23457E+15. The format is only a display; widening the column or applying Format > Number > Plain text changes nothing for digits already lost.
Decimal and thousands marks
A European file may contain 1.234,56, meaning one thousand two hundred thirty-four and fifty-six hundredths. In a US-locale sheet this is text, because the order of the marks is invalid. Worse, 1,5 in a comma-delimited file would be split into two columns unless the field is quoted. Two fixes:
- Set the locale to one that uses the decimal comma (for example Germany or France) before importing. Use the Semicolon separator if the file separates columns with semicolons.
- Repair the text with SUBSTITUTE:
=VALUE(SUBSTITUTE(SUBSTITUTE(A2, ".", ""), ",", "."))The formula removes the thousands dots, changes the decimal comma to a dot and converts the result. It assumes the sheet's locale uses a dot decimal.
Percentages, currency and booleans
12%becomes 0.12 formatted as a percentage. This is correct, but a sum of the column uses 0.12, not 12.$1,234.50becomes the number 1234.5 with currency formatting in a US locale. In another locale the$or the comma may be unrecognised, and the field stays text.TRUEandFALSEbecome real booleans, which show as checkbox-like logical values and behave as 1 and 0 in arithmetic. A column of product codes that happens to includeTRUEis converted too.
Fields that look like formulas
With conversion on, a field starting with = is treated as a formula. A text such as =A1+1 calculates, and a value such as =SUM( produces #ERROR!. A field beginning with + or - may also be read as a formula or number.
This matters for security as well. A CSV from an untrusted source can contain formulas such as =IMPORTXML(...) that fetch external data when opened. For files you did not produce, import with conversion off and inspect the data first.
Invisible characters
Exports from web pages and other systems often include non-breaking spaces (character code 160). TRIM removes ordinary spaces but not these. A value that looks like Paris will not match Paris in a lookup if one has a hidden space.
Finding type problems
You can diagnose most problems in under a minute.
- Alignment: by default numbers and dates align right, text aligns left. A left-aligned date column means the dates are text.
- Test formulas:
ISNUMBER,ISTEXTandTYPEreport the real type of a cell. - Count comparison:
COUNTcounts numbers and dates, whileCOUNTAcounts all non-empty cells. If they differ for a column that should be uniform, some cells are the wrong type.
This formula flags the cells in a column that are not numbers:
=ARRAYFORMULA(IF(A2:A="", "", NOT(ISNUMBER(A2:A))))Rows showing TRUE need attention. Add a filter on that helper column to list only the bad rows.
For text that is only dirty, not mistyped, clean a whole column at once. Replace the ordinary-space trim with a version that handles the non-breaking space too:
=ARRAYFORMULA(TRIM(SUBSTITUTE(A2:A, CHAR(160), " ")))Plain =ARRAYFORMULA(TRIM(A2:A)) is enough when the problem is only extra regular spaces.
A decision path
Summary of symptoms and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| `00501` shows as `501` | Conversion turned the text into a number | Re-import with conversion off, or `=TEXT(A2, "00000")` |
| Day and month swapped | Locale differs from the file's | Set locale, then re-import |
| Some dates are text | Day above 12 in a month-first locale | Set locale, or build with DATE |
| Last digits of an ID are zeros | More than 15 digits imported as a number | Re-import with conversion off |
| `1.234,56` stays text | Decimal comma in a dot-decimal locale | Change locale or use SUBSTITUTE and VALUE |
| Lookup fails on text that looks equal | Extra or non-breaking spaces | TRIM with SUBSTITUTE on CHAR(160) |
Exercise
A CSV contains order IDs such as 0004721 and a date column with 05/06/2026, where the file was exported by a UK system. Your spreadsheet locale is United States. Which settings do you choose before importing, and why?
Show answer
Set the spreadsheet locale to United Kingdom first, so 05/06/2026 is read as June 5 and not May 6. Then import with "Convert text to numbers, dates, and formulas" off to keep the leading zeros in the order IDs. Because conversion is off, the date column arrives as text, so convert it afterwards with DATEVALUE (which uses the UK locale) and leave the order IDs as text.
Exercise
A column of ZIP codes shows 1234 for what should be 01234. All codes in the file are five digits. Write a formula to restore them and name one reason to prefer re-importing instead.
Show answer
Use =TEXT(A2, "00000"), then paste the results as values only. Re-importing with conversion off is better when the column mixes lengths, because a fixed pad width would then be wrong for some codes. It also avoids repairing other columns in the same file that were damaged in the same way.
Exercise
A lookup between two imported columns fails even though both cells display Lyon. TRIM did not fix it. What is the likely cause, and what formula fixes the whole column?
Show answer
One of the cells probably contains a non-breaking space (CHAR(160)), which TRIM does not remove. Use =ARRAYFORMULA(TRIM(SUBSTITUTE(A2:A, CHAR(160), " "))) to replace those characters with ordinary spaces and then trim.