# How to handle leading zeros and precision in number codes

You may sometimes use social security, phone, and postal code numbers in your Office Excel data. What do these numbers have in common? Each of them is a number code that you don't use to count, but you may want to store them as numbers anyway. Unfortunately, Excel removes leading zeros that you may want to stay right where they are. Here's how to make Excel handle leading zeros in number codes the way that you want.

If you are using credit card numbers, or other number codes that contain 16 digits or more, you must use a text format because Excel has a maximum of 15 digits of precision and will round any numbers that follow the 15th digit down to zero.

## The number format removes leading zeros by default

Number codes get into your Excel workbook in many ways. You might simply type them in, or copy and paste them from another program. Or, you might open a text file, or import data from a data source, such as an Access database. In many cases, Excel converts these number codes to a general or a number format. The default behavior of those formats is to remove any leading zeros and, depending on the length of the number, use scientific notation. You see, Excel treats a number code as just another number, but you know that it's a number code, and that the leading zeros need to stay put.

 Number code Fictitious example Default behaviors (varies with cell width) Socialsecurity 012345678 123456781.2E+07 Phone 0014255550177 142555501771.4E+10 Postalcode 00123 123

You might not even see this happen if you are dealing with a long list of number codes. So it's important to be aware of the issue, especially when the data is used in other programs. Although you can convert the number format to a text format, you may not want to convert numbers to text, especially if you have a large list of long numbers, because this can increase the size of your workbook.

## Use a custom or special format to keep the leading zeros

For number codes that contain fewer than 16 digits, if you want to resolve the issue just within the workbook because it's not used by other programs as a data source, you can use a custom or a special format to keep the leading zeros.

In addition, you can separate some of the digits in your number codes with dashes by adding these dashes to the custom format. For example, to make a phone number more readable, you can add a dash between the international code, the country/region code, the area code, the prefix, and the last few numbers.

 Number code Fictitious example Number format and new behavior Social security 012345678 000-00-0000 012-34-5678 Phone 0012345556789 00-0-000-000-0000 00-1-234-555-6789 Postalcode 00123 00000 00123

Procedure

1. Select the cell or range of cells that you want to format.

How to select a cell or a range

Tip: To cancel a selection of cells, click any cell on the worksheet.

2. On the Home tab, click the Dialog Box Launcher next to Number.

3. In the Category box, click Custom and then, in the Type box, type the number format, such as 000-00-0000 for a social security number code, or 00000 for a postal code.

Tip: You can also click Special, and then select Zip Code, Zip Code + 4, Phone number, or Social Security Number.

### Use a formula or calculated column

If you are using another program that opens the workbook as a data source, you should confirm to see how that program handles leading zeros. For example, you have a list of addresses in a workbook that you want to use as a data source to a Mail Merge operation, and one of the columns is a zip code with a custom format of 00000. Office Access keeps the leading zeros, but Office Word removes the leading zeros. In the case of Word, you can specify a calculated column as the postal code field in the Mail Merge operation to ensure that the leading zeros are not removed.

 Number code Fictitious example (In cell A1) TEXT function and new behavior Socialsecurity 012345678 =TEXT(A1,"000-00-0000")012-34-5678 Phone 0012345556789 =TEXT(A1,"00-0-000-000-0000")00-1-234-555-6789 Postalcode 00123 =TEXT(A1,"00000")00123

### Credit card number codes are rounded down

To further complicate the matter, Excel has a maximum precision of 15 significant digits, which means that for any number containing 16 or more digits, such as a credit card number, the last digit is rounded down to zero.

 Number code Fictitious example Default behaviors (varies with cell width) Creditcard 0123456789012345 1.23457E+14

Even if you use a custom number format, the number is still rounded down to zero when there is no leading zero.

 Number code Fictitious example Number format and new behavior Credit card(Withleadingzero) 0123456789012345 0000-0000-0000-00000123-4567-8901-2345 Credit card(Withoutleadingzero) 1234567890123456 0000-0000-0000-00001234-5678-9012-3450

In the case of number codes that are 16 digits or larger, you must use a text format.

### Convert the number code to a text format

To convert a number code, such as a credit card number to text format, you can do the following:

#### Use the apostrophe character

For a small set of numbers, you can type an apostrophe character (') in front of the number code and then add back the leading zeros.

#### Convert the number to text when you import text data

In Step 3 of the Text Import Wizard (On the Data tab, in the Get External Data group, click From Text), you can select the column of data that contains the credit card number, and then explicitly choose a Text column data format.

Share