Formatting Numbers, Dates, and Times
One of the best ways to improve the readability of your worksheets is to display your data in a format that is logical, consistent, and straightforward. Formatting currency amounts with leading dollar signs, percentages with trailing percent signs, and large numbers with commas are a few of the ways you can improve your spreadsheet style.
This section shows you how to format numbers, dates, and times using Excel's built-in formatting options. You'll also learn how to create your own formats to gain maximum control over the appearance of your data.
Numeric Display Formats
When you enter numbers in a worksheet, Excel removes any leading or trailing zeros. For example, if you enter 0123.4500, Excel displays 123.45. The exception to this rule occurs when you enter a number that is wider than the cell. In this case, Excel usually expands the width of the column to fit the number. However, in some cases, Excel tailors the number to fit the cell by rounding off some decimal places. For example, a number such as 123.45678 is displayed as 123.4568. Note that, in this case, the number is changed for display purposes only; Excel still retains the original number internally.
When you create a worksheet, each cell uses this format, known as the General number format, by default. If you want your numbers to appear differently, you can choose from among Excel's seven categories of numeric formats: Number, Currency, Accounting, Percentage, Fraction, Scientific, and Special:
- Number formats—The number formats have three components: the number of decimal places (0–30), whether the thousands separator (,) is used, and how negative numbers are displayed. For negative numbers, you can display the number with a leading minus sign, in red, surrounded by parentheses, or in red surrounded by parentheses.
- Currency formats—The currency formats are similar to the number formats, except that the thousands separator is always used, and you have the option of displaying the numbers with a leading dollar sign ($) or some other currency symbol.
- Accounting formats—With the accounting formats, you can select the number of decimal places and whether to display a leading dollar sign (or other currency symbol). If you do use a dollar sign, Excel displays it flush left in the cell. All negative entries are displayed surrounded by parentheses.
- Percentage formats—The percentage formats display the number multiplied by 100 with a percent sign (%) to the right of the number. For example, .506 is displayed as 50.6%. You can display 0–30 decimal places.
- Fraction formats—The fraction formats enable you to express decimal quantities as fractions. There are nine fraction formats in all, including displaying the number as halves, quarters, eighths, sixteenths, tenths, and hundredths.
- Scientific formats—The scientific formats display the most significant number to the left of the decimal, 2–30 decimal places to the right of the decimal, and then the exponent. So, 123000 is displayed as 1.23E+05.
-
Special formats—The special formats are a collection designed to take care of special cases. Here's a list of the special formats, with some examples:
Format
Enter This
It Displays as This
ZIP code
1234
01234
ZIP code + 4
123456789
12345-6789
Phone number
1234567890
(123) 456-7890
Social Security number
123456789
123-45-6789
Changing Numeric Formats
The quickest way to format numbers is to specify the format as you enter your data. For example, if you begin a dollar amount with a dollar sign ($), Excel automatically formats the number as currency. Similarly, if you type a percent sign (%) after a number, Excel automatically formats the number as a percentage. Here are a few more examples of this technique. Note that you can enter a negative value using either the negative sign (–) or parentheses.
Number Entered |
Number Displayed |
Format Used |
$1234.567 |
$1,234.57 |
Currency |
($1234.5) |
($1,234.50) |
Currency |
10% |
10% |
Percentage |
123E+02 |
1.23E+04 |
Scientific |
5 3/4 |
5 3/4 |
Fraction |
0 3/4 |
3/4 |
Fraction |
3/4 |
4–Mar |
Date |
Specifying the numeric format as you enter a number is fast and efficient because Excel guesses the format you want to use. Unfortunately, Excel sometimes guesses wrong (for example, interpreting a simple fraction as a date). In any case, you don't have access to all the available formats (for example, displaying negative dollar amounts in red). To overcome these limitations, you can select your numeric formats from a list. Here are the steps to follow:
- Select the cell or range of cells to which you want to apply the new format.
- Choose the Home tab.
- Pull down the Number Format list. Excel displays its built-in formats, as shown in Figure 3.13. Under the name of each format, Excel shows you how the current cell would be displayed if you chose that format.
Figure 3.13 In the Home tab, pull down the Number Format list to see all of Excel's built-in numeric formats.
- Click the format you want to use.
For more numeric formatting options, use the Number tab of the Format Cells dialog box. Select the cell or range and then choose Home, Number Format, More Number Formats (or press Ctrl+1). As you can see in Figure 3.14, when you click a numeric format in the Category list, Excel displays more formatting options, such as the Decimal Places spin box. (The options you see depend on the category you choose.) The Sample information box shows a sample of the format applied to the current cell's contents.
Figure 3.14 When you choose a format in the Category list, Excel displays the format's options.
As an alternative to the Format Cells dialog box, Excel offers several keyboard shortcuts for setting the numeric format. Select the cell or range you want to format, and use one of the key combinations listed in Table 3.6.
Table 3.6. Shortcut Keys for Selecting Numeric Formats
Shortcut Key |
Format |
Ctrl+~ |
General |
Ctrl+! |
Number (two decimal places; using thousands separator) |
Ctrl+$ |
Currency (two decimal places; using dollar sign; negative numbers surrounded by parentheses) |
Ctrl+% |
Percentage (zero decimal places) |
Ctrl+^ |
Scientific (two decimal places) |
If your mouse is nearby, you can use the controls in the Home tab's Number group as another method of selecting numeric formats. The Number Format list (see Figure 3.13) lists all the formats. Here are the other controls that appear in this group:
Button |
Format |
Accounting Style |
Accounting (two decimal places; using dollar sign) |
Percent Style |
Percentage (zero decimal places) |
Comma Style |
Number (two decimal places; using thousands separator) |
Increase Decimal |
Increases the number of decimal places in the current format |
Decrease Decimal |
Decreases the number of decimal places in the current format |
Customizing Numeric Formats
Excel numeric formats give you lots of control over how your numbers are displayed, but they have their limitations. For example, no built-in format enables you to display a number such as 0.5 without the leading zero, or to display temperatures using, for example, the degree symbol.
To overcome these and other limitations, you need to create your own custom numeric formats. You can do this either by editing an existing format or by entering your own from scratch. The formatting syntax and symbols are explained in detail later in this section.
Every Excel numeric format, whether built-in or customized, has the following syntax:
positive format;negative format;zero format;text format
The four parts, separated by semicolons, determine how various numbers are presented. The first part defines how a positive number is displayed, the second part defines how a negative number is displayed, the third part defines how zero is displayed, and the fourth part defines how text is displayed. If you leave out one or more of these parts, numbers are controlled as shown here:
Number of Parts Used |
Format Syntax |
Three |
positive format;negative format;zero format . |
Two |
positive and zero format; negative format . |
One |
positive, negative, and zero format . |
Table 3.7 lists the special symbols you use to define each of these parts.
Table 3.7. Numeric Formatting Symbols
Symbol |
Description |
General |
Displays the number with the General format. |
# |
Holds a place for a digit and displays the digit exactly as typed. Displays nothing if no number is entered. |
0 |
Holds a place for a digit and displays the digit exactly as typed. Displays 0 if no number is entered. |
? |
Holds a place for a digit and displays the digit exactly as typed. Displays a space if no number is entered. |
. (period) |
Sets the location of the decimal point. |
, (comma) |
Sets the location of the thousands separator. Marks only the location of the first thousand. |
% |
Multiplies the number by 100 (for display only) and adds the percent (%) character. |
E+ e+ E- e- |
Displays the number in scientific format. E- and e- place a minus sign in the exponent; E+ and e+ place a plus sign in the exponent. |
/ (slash) |
Sets the location of the fraction separator. |
$ ( ) : - + <space> |
Displays the character. |
* |
Repeats whatever character immediately follows the asterisk until the cell is full. Doesn't replace other symbols or numbers. |
_ (underscore) |
Inserts a blank space the width of whatever character follows the underscore. |
\ (backslash) |
Inserts the character that follows the backslash. |
"text" |
Inserts the text that appears within the quotation marks. |
@ |
Holds a place for text. |
[COLOR] |
Displays the cell contents in the specified color. |
[condition value] |
Uses conditional statements to specify when the format is to be used. |
Before looking at some examples, let's run through the basic procedure. To customize a numeric format, select the cell or range you want to format and then follow these steps:
- Choose Home, Number Format, More Number Formats (or press Ctrl+1) and select the Number tab, if it's not already displayed.
- In the Category list, click Custom.
- If you're editing an existing format, choose it in the Type list box.
- Edit or enter your format code.
- Click OK. Excel returns you to the worksheet with the custom format applied.
Excel stores each new format definition in the Custom category. If you edited an existing format, the original format is left intact and the new format is added to the list. You can select the custom formats the same way you select the built-in formats. To use your custom format in other workbooks, you copy a cell containing the format to that workbook. Figure 3.15 shows a dozen examples of custom formats.
Figure 3.15 Sample custom numeric formats.
Here's a quick explanation for each example:
- Example 1—These formats show how you can reduce a large number to a smaller, more readable one by using the thousands separator. A format such as 0,000.0 would display, for example, 12300 as 12,300.0. If you remove the three zeros between the comma and the decimal (to get the format 0,.0), Excel displays the number as 12.3 (although it still uses the original number in calculations). In essence, you've told Excel to express the number in thousands. To express a larger number in millions, you just add a second thousands separator.
- Example 2—Use this format when you don't want to display any leading or trailing zeros.
- Example 3—These are examples of four-part formats. The first three parts define how Excel should display positive numbers, negative numbers, and zero. The fourth part displays the message Enter a number if the user enters text in the cell.
-
Example 4—In this example, the cents sign (¢) is used after the value. To enter the cents sign, press Alt+0162 on your keyboard's numeric keypad. (This won't work if you use the numbers along the top of the keyboard.) Table 3.8 shows some common ANSI characters you can use.
Table 3.8. ANSI Character Key Combinations
Key Combination
ANSI Character
Alt+0162
¢
Alt+0163
£
Alt+0165
¥
Alt+0169
©
Alt+0174
®
Alt+0176
°
- Example 5—This example adds the text string "Dollars" to the format.
- Example 6—In this example, an M is appended to any number, which is useful if your spreadsheet units are in megabytes.
- Example 7—This example uses the degree symbol (°) to display temperatures.
- Example 8—The three semicolons used in this example result in no number being displayed (which is useful as a basic method for hiding a sensitive value).
- Example 9—This example shows that you can get a number sign (#) to display in your formats by preceding # with a backslash (\).
- Example 10—In this example, you see a trick for creating dot trailers. Recall that the asterisk (*) symbol fills the cell with whatever character follows it. So, creating a dot trailer is a simple matter of adding "*." to the end of the format.
- Example 11—This example shows a similar technique that creates a dot leader. Here the first three semicolons display nothing; then comes "*.", which runs dots from the beginning of the cell up to the text (represented by the @ sign).
- Example 12—This example shows a format that's useful for entering stock quotations.
Hiding Zeros
Worksheets look less cluttered and are easier to read if you hide unnecessary zeros. Excel enables you to hide zeros either throughout the entire worksheet or only in selected cells.
To hide all zeros, choose Office, Excel Options; choose the Advanced tab in the Excel Options dialog box; and clear the Show a Zero In Cells That Have Zero Value check box.
To hide zeros in selected cells, create a custom format that uses the following format syntax:
positive format;negative format;
The extra semicolon at the end acts as a placeholder for the zero format. Because there's no definition for a zero value, nothing is displayed. For example, the format $#,##0.00_);($#,##0.00); displays standard dollar values, but it leaves the cell blank if it contains zero.
Using Condition Values
The action of the formats you've seen so far have depended on whether the cell contents were positive, negative, zero, or text. Although this is fine for most applications, sometimes you need to format a cell based on different conditions. For example, you might want only specific numbers, or numbers within a certain range, to take on a particular format. You can achieve this effect by using the [condition value] format symbol. With this symbol, you set up conditional statements using the logical operators =, <, >, <=, >=, and <>, and the appropriate numbers. You then assign these conditions to each part of your format definition.
For example, suppose that you have a worksheet for which the data must be within the range -1,000 and 1,000. To flag numbers outside this range, you set up the following format:
[>=1000]"Error: Value >= 1,000";[<=-1000]"Error: Value <= -1,000";0.00
The first part defines the format for numbers greater than or equal to 1,000 (an error message). The second part defines the format for numbers less than or equal to –1,000 (also an error message). The third part defines the format for all other numbers (0.00).
→ |
You're better off using Excel's extensive conditional formatting features; see "Applying Conditional Formatting to a Range," p. 24. |
Date and Time Display Formats
If you include dates or times in your worksheets, you need to make sure that they're presented in a readable, unambiguous format. For example, most people would interpret the date 8/5/07 as August 5, 2007. However, in some countries, this date would mean May 8, 2007. Similarly, if you use the time 2:45, do you mean a.m. or p.m.? To avoid these kinds of problems, you can use Excel's built-in date and time formats, listed in Table 3.9.
Table 3.9. Excel's Date and Time Formats
Format |
Display |
m/d |
8/3 |
m/d/yy |
8/3/07 |
mm/dd/yy |
08/03/07 |
d-mmm |
3-Aug |
d-mmm-yy |
3-Aug-07 |
dd-mmm-yy |
03-Aug-07 |
mmm-yy |
Aug-07 |
mmmm-yy |
August-07 |
mmmm d, yyyy |
August 3, 2007 |
h:mm AM/PM |
3:10 PM |
h:mm:ss AM/PM |
3:10:45 PM |
h:mm |
15:10 |
h:mm:ss |
15:10:45 |
mm:ss.0 |
10:45.7 |
[h]:[mm]:[ss] |
25:61:61 |
m/d/yy h:mm AM/PM |
8/23/07 3:10 PM |
m/d/yy h:mm |
8/23/07 15:10 |
The [h]:[mm]:[ss] format requires a bit more explanation. You use this format when you want to display hours greater than 24 or minutes and seconds greater than 60. For example, suppose that you have an application in which you need to sum several time values (such as the time you've spent working on a project). If you add, say, 10:00 and 15:00, Excel normally shows the total as 1:00 (because, by default, Excel restarts times at 0 when they hit 24:00). To display the result properly (that is, as 25:00), use the format [h]:00.
You use the same methods you used for numeric formats to select date and time formats. In particular, you can specify the date and time format as you input your data. For example, entering Jan-07 automatically formats the cell with the mmm-yy format. Also, you can use the following shortcut keys:
Shortcut Key |
Format |
Ctrl+# |
d—mmm—yy |
Ctrl+@ |
h:mm AM/PM |
Ctrl+; |
Current date (m/d/yy) |
Ctrl+: |
Current time (h:mm AM/PM) |
Customizing Date and Time Formats
Although the built-in date and time formats are fine for most applications, you might need to create your own custom formats. For example, you might want to display the day of the week (for example, Friday). Custom date and time formats generally are simpler to create than custom numeric formats. There are fewer formatting symbols, and you usually don't need to specify different formats for different conditions. Table 3.10 lists the date and time formatting symbols.
Table 3.10. The Date and Time Formatting Symbols
Symbol |
Description |
Date Formats |
|
d |
Day number without a leading zero (1–31) |
dd |
Day number with a leading zero (01–31) |
ddd |
Three-letter day abbreviation (Mon, for example) |
dddd |
Full day name (Monday, for example) |
m |
Month number without a leading zero (1–12) |
mm |
Month number with a leading zero (01–12) |
mmm |
Three-letter month abbreviation (Aug, for example) |
mmmm |
Full month name (August, for example) |
yy |
Two-digit year (00–99) |
yyyy |
Full year (1900–2078) |
Time Formats |
|
h |
Hour without a leading zero (0–24) |
hh |
Hour with a leading zero (00–24) |
m |
Minute without a leading zero (0–59) |
mm |
Minute with a leading zero (00–59) |
s |
Second without a leading zero (0–59) |
ss |
Second with a leading zero (00–59) |
AM/PM, am/pm, A/P |
Displays the time using a 12-hour clock |
/ : . – |
Symbols used to separate parts of dates or times |
[COLOR] |
Displays the date or time in the color specified |
[condition value] |
Uses conditional statements to specify when the format is to be used |
Figure 3.16 shows some examples of custom date and time formats.
Figure 3.16 Sample custom date and time formats.
Deleting Custom Formats
The best way to become familiar with custom formats is to try your own experiments. Just remember that Excel stores each format you try. If you find that your list of custom formats is getting a bit unwieldy or that it's cluttered with unused formats, you can delete formats by following the steps outlined here:
- Choose Home, Number Format, More Number Formats.
- Click the Custom category.
- Click the format in the Type list box. (Note that you can delete only the formats you've created yourself.)
- Click Delete. Excel removes the format from the list.
- To delete other formats, repeat steps 2 through 4.
- Click OK. Excel returns you to the spreadsheet.
From Here
- To learn about conditional formatting, see "Applying Conditional Formatting to a Range," p. 24.
- To learn how to solve formula problems, see "Troubleshooting Formulas," p. 113.
- To get the details on text formulas and functions, see "Working with Text Functions," p. 143.
- If you want to use logical worksheet functions in your comparison formulas, see "Adding Intelligence with Logical Functions," p. 167.
- To learn how to create and use data tables, see "Using What-If Analysis," p. 361.