Sub topic 4
Keeping leading zeros, long numbers, and fractions as you intend
This chapter assumes you can type into a cell and press Enter, and that you know the previous chapter's idea: Excel decides whether an entry is text, a number, a date, or a formula. Here you will learn where that guess goes wrong for zip codes, product codes, card numbers, and fractions. You will also learn how to override it.
Why Excel changes what you type
When you commit an entry, Excel tries to read it as a number first. If it can, it stores the number and drops anything that does not change the value. That is why 00123 becomes 123, and why a 16-digit card number loses its last digits.
Three common cases fall into this pattern:
- Leading zeros are removed because
00123and123are the same number. - Numbers longer than 15 significant digits are cut off and padded with zeros.
- Fractions such as
1/2are read as dates.
Each has a fix. The fixes work in one of two ways. Either you tell Excel to store the entry as text, or you keep it as a number and change only how it looks.
Keeping leading zeros
Identifiers like zip codes (02134), employee IDs, and product codes look like numbers but are labels. You do not add them or average them. Store them as text.
Option 1: type an apostrophe first
Type an apostrophe before the digits:
'00123Excel stores 00123 as text. The apostrophe is not part of the value. It does not appear in the cell, but you will see it in the formula bar when the cell is selected. Because the cell now holds text, it is left-aligned by default, and Excel may show a small green triangle in the corner. The triangle is the "Number stored as text" warning. For identifiers, you can ignore it or turn it off from the warning menu.
Option 2: format the cell as Text first
Select the cells, then on the Home tab open the Number Format box and choose Text. Anything you type afterward in those cells stays as typed.
The order matters. If you type 00123 first and apply Text afterward, the zeros are already gone. Excel does not bring them back. Apply the format before you enter the data.
Option 3: keep a number and add zeros with a format
If the cell must stay a real number, use a custom number format. Select the cells, press Ctrl+1, choose Custom, and enter 00000 as the format code. A stored 123 now displays as 00123. The stored value is still 123. Formulas see the number, and the display is padded to five digits.
Option 4: build the padded text with a formula
If the source number is in another cell, a formula can produce padded text:
=TEXT(A1,"00000")If A1 holds 123, the result is the text 00123. Unlike a custom format, this changes the value itself. The result is text, not a number.
Choosing between them
| Method | Stored value | Good for | Watch out for |
|---|---|---|---|
| Apostrophe | Text | A few one-off entries | Easy to forget on each entry |
| Text format | Text | Whole columns you will type or paste into | Must be applied before entry |
| Custom format `00000` | Number | IDs you still need to treat as numbers | Copying the value to a text file may drop the zeros |
| `TEXT` formula | Text (in the formula cell) | Padding values that already exist elsewhere | Result depends on the source cell |
Long numbers
Excel keeps only 15 significant digits of precision. If you type a 16-digit number such as 1234567890123456, Excel stores 1234567890123450. The last digit is replaced with a zero, and you cannot recover it. Very long numbers may also display in scientific notation, for example 1.23457E+15.
This is a limit of the number type. Widening the column or changing the display does not restore lost digits.
The fix is to store the entry as text, using the apostrophe or the Text format described above:
'1234567890123456Now all 16 digits are kept, because text has no precision limit in this sense. The trade-off is that you cannot do arithmetic on it. For card numbers, tracking numbers, and long account IDs, that is usually what you want.
The same rule applies when you paste. If you paste a column of long IDs into General cells, they are converted and truncated on the way in. Format the destination as Text first.
Scientific notation has a second cause. Even short numbers can show as 1.2E+05 if the column is too narrow for General format. In that case the stored value is fine, and widening the column fixes the display.
Fractions
If you type 1/2 into a cell, Excel usually reads it as a date, such as 2-Jan or January 2 of the current year, depending on your regional settings. The cell then stores a date serial number, not 0.5.
To enter a fraction as a number, type a whole-number part, a space, and then the fraction. For a plain fraction, use zero as the whole part:
Type 0 1/2 in a cell and press EnterExcel stores the number 0.5 and displays it as 1/2. In the formula bar you will see 0.5. The cell has a Fraction number format, which Excel applied automatically.
For a mixed number, replace the zero. Typing 3 1/4 stores 3.25 and displays 3 1/4.
A few details are worth knowing:
- Excel reduces fractions in the display only if the format allows it. Typing
0 2/4typically displays1/2. - The fraction format chooses a denominator that fits. You can choose a specific one, such as sixteenths, from Format Cells > Number > Fraction.
- A fraction that does not match any available denominator is shown as the nearest one, so the display can be an approximation of the stored value.
- If you format a cell as Fraction before typing, typing
1/2directly works as expected.
Checking what you actually stored
After entering one of these values, confirm what Excel kept:
- Select the cell and read the formula bar. It shows the stored value, not the displayed one.
- Look at the alignment. Text is left-aligned by default and numbers are right-aligned, unless someone changed it.
- Check the Number Format box on the Home tab. It shows General, Text, Fraction, or Custom.
- Use
=ISTEXT(A1)or=ISNUMBER(A1)in another cell if you are unsure.
Common mistakes
- Formatting after typing. Text format applied later does not restore zeros or lost digits. Retype the entries.
- Sorting mixed columns. Numbers and text sort separately. If some IDs are numbers and some are text, they will not group the way you expect.
- Using
TEXTand expecting a number. The result is text. Wrapping it inVALUEgives a number again and drops the zeros. - Opening CSV files. Excel converts columns on open, so zeros and long digits can disappear before you see the file. Use Data > From Text/CSV and set those columns to Text during import.
- Assuming the apostrophe is data. It is a prefix marker. It is not stored in the text, and it does not count in
LEN.
Exercise
You type 0045 into a cell and press Enter, and the cell shows 45. Name two ways to end up with 0045 displayed, and say which one keeps the cell as a number.
Show answer
Option 1: retype the entry with an apostrophe first ('0045), or format the cell as Text and then retype 0045. Both store text. Option 2: enter 45, then apply the custom number format 0000. This keeps the cell a number that displays as 0045.
Exercise
A colleague types the 16-digit number 4111111111111111 into a General cell. It displays as 4.11111E+15, and after you widen the column and apply Text format, it reads 4111111111111110. Why, and how do you prevent it?
Show answer
Excel stores only 15 significant digits for a number, so the final digit was replaced with zero when the entry was committed. Applying Text later cannot restore it. Format the cell as Text (or start with an apostrophe) before entering the number.
Exercise
You want a cell to hold the value 0.5 displayed as 1/2. What do you type, and why does typing 1/2 alone often fail?
Show answer
Type 0 1/2 (zero, a space, then 1/2). Typing 1/2 alone is usually interpreted as a date, so the cell stores a date serial number instead of 0.5.