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 formatsThe number formats have three components: the number of decimal places (030), 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 formatsThe 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 formatsWith 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 formatsThe 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 030 decimal places.
Fraction formatsThe 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 formatsThe scientific formats display the most significant number to the left of the decimal, 230 decimal places to the right of the decimal, and then the exponent. So, 123000 is displayed as 1.23E+05.
Special formatsThe 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 |
4Mar |
Date |
NOTE
Excel interprets a simple fraction such as 3/4 as a date (March 4, in this case). Always include a leading zero, followed by a space, if you want to enter a simple fraction from the formula bar.
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 Format, Cells (or press Ctrl+1). The Format Cells dialog box appears.
Choose the Number tab, if it's not already displayed.
Select the format you want to use in the Category list box. Excel displays the various options available for the category you choose. For example, Figure 3.13 shows the options that appear when you choose the Number format.
Choose the formatting options you want to use. The Sample information box shows a sample of the format applied to the current cell's contents.
Click OK. Excel returns you to the worksheet with the new formatting applied.
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.5.
Figure 3.13 When you choose a format in the Category list, Excel displays the format's options.
Table 3.5 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 tools in the Formatting toolbar as another method of selecting numeric formats. Here are the four available tools (see Figure 3.13):
Button |
Format |
Currency 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 0.5 without the leading zero, or to display temperatures using, say, 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.6 lists the special symbols you use to define each of these parts.
Table 3.6 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 Format, Cells (or press Ctrl+1) and select the Number tab, if it's not already displayed.
In the Category list, choose 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.14 shows a dozen examples of custom formats.
Figure 3.14 Sample custom numeric formats.
Here's a quick explanation for each example:
Example 1These 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, say, 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 2Use this format when you don't want to display any leading or trailing zeros.
Example 3These 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 4In 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.7 shows some common ANSI characters you can use.
Table 3.7 ANSI Character Key Combinations
Key Combination |
ANSI Character |
Alt+0163 |
£ |
Alt+0162 |
¢ |
Alt+0165 |
x |
Alt+0169 |
© |
Alt+0174 |
® |
Alt+0176 |
° |
Example 5This example adds the text string "Dollars" to the format.
Example 6In this example, an M is appended to any number, which is useful if your spreadsheet units are in megabytes.
Example 7This example uses the degree symbol (°) to display temperatures.
Example 8The three semicolons used in this example result in no number being displayed (which is useful as a basic method for hiding sensitive values).
Example 9This example shows that you can get a number sign (#) to display in your formats by preceding # with a backslash (\).
Example 10In 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 te end of the format.
Example 11This 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 12This 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 Tools, Options; choose the View tab in the Options dialog box; and clear the Zero Values 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.
TIP
If your worksheet contains only integers (no fractions or decimal places), you can use the format #,### to hide zeros.
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).
NOTE
Excel also enables you to apply a particular font automatically when a cell meets a specified condition. This is called conditional formatting, and you apply it by choosing Format, Conditional Formatting. To construct the condition for a value, choose Cell Value Is in the first list, and then select a comparison operator (such as Between or Less Than) in the second list. You then enter one or two values (depending on the operator). Finally, click Format to select the font formatting to apply to the cell when the condition is met.
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/04 as August 5, 2004. However, in some countries, this date would mean May 8, 2004. 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.8.
Table 3.8 Excel's Date and Time Formats
Format |
Display |
m/d |
8/3 |
m/d/yy |
8/3/05 |
mm/dd/yy |
08/03/05 |
d-mmm |
3-Aug |
d-mmm-yy |
3-Aug-05 |
dd-mmm-yy |
03-Aug-05 |
mmm-yy |
Aug-05 |
mmmm-yy |
August-05 |
mmmm d, yyyy |
August 3, 2005 |
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/94 3:10 PM |
m/d/yy h:mm |
8/23/94 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-04 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) |
TIP
Excel for the Macintosh uses a different date system than Excel for Windows uses. If you share files between these environments, you need to use Macintosh dates in your Excel for Windows worksheets to maintain the correct dates when you move from one system to another. Select Tools, Options; choose the Calculation tab; and activate the 1904 Date System check box.
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.9 lists the date and time formatting symbols.
Table 3.9 The Date and Time Formatting Symbols
Symbol |
Description |
Date Formats |
|
d |
Day number without a leading zero (131) |
dd |
Day number with a leading zero (0131) |
ddd |
Three-letter day abbreviation (Mon, for example) |
dddd |
Full day name (Monday, for example) |
m |
Month number without a leading zero (112) |
mm |
Month number with a leading zero (0112) |
mmm |
Three-letter month abbreviation (Aug, for example) |
mmmm |
Full month name (August, for example) |
yy |
Two-digit year (0099) |
yyyy |
Full year (19002078) |
Time Formats |
|
h |
Hour without a leading zero (024) |
hh |
Hour with a leading zero (0024) |
m |
Minute without a leading zero (059) |
mm |
Minute with a leading zero (0059) |
s |
Second without a leading zero (059) |
ss |
Second with a leading zero (0059) |
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.15 shows some examples of custom date and time formats.
Figure 3.15 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 Format, Cells, and then choose the Number tab in the Options dialog box.
Choose the Custom category.
Select 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 24.
Click OK. Excel returns you to the spreadsheet.
From Here
For more information on using Excel's intersection operator, see "Using the Intersection Operator," p. 34.
To learn how to solve formula problems, see "Troubleshooting Formulas," p. 107.
To get the details on text formulas and functions, see "Working with Text Functions," p.133.
If you want to use logical worksheet functions in your comparison formulas, see "Adding Intelligence with Logical Functions," p. 155.
To learn how to create and use data tables, see "Using What-If Analysis," p. 315.