In Excel, you can format numbers in cells for things like currency, percentages, decimals, dates, phone numbers, or social security numbers.
-
Select a cell or a cell range.
-
On the Home tab, select Number from the drop-down.
Or, you can choose one of these options:-
Press CTRL + 1 and select Number.
-
Right-click the cell or cell range, select Format Cells… , and select Number.
-
Select the small arrow, dialog box launcher, and then select Number.
-
-
Select the format you want.
Number formats
To see all available number formats, click the Dialog Box Launcher next to Number on the Home tab in the Number group.
Format |
Description |
---|---|
General |
The default number format that Excel applies when you type a number. For the most part, numbers that are formatted with the General format are displayed just the way you type them. However, if the cell is not wide enough to show the entire number, the General format rounds the numbers with decimals. The General number format also uses scientific (exponential) notation for large numbers (12 or more digits). |
Number |
Used for the general display of numbers. You can specify the number of decimal places that you want to use, whether you want to use a thousands separator, and how you want to display negative numbers. |
Currency |
Used for general monetary values and displays the default currency symbol with numbers. You can specify the number of decimal places that you want to use, whether you want to use a thousands separator, and how you want to display negative numbers. |
Accounting |
Also used for monetary values, but it aligns the currency symbols and decimal points of numbers in a column. |
Date |
Displays date and time serial numbers as date values, according to the type and locale (location) that you specify. Date formats that begin with an asterisk (*) respond to changes in regional date and time settings that are specified in Control Panel. Formats without an asterisk are not affected by Control Panel settings. |
Time |
Displays date and time serial numbers as time values, according to the type and locale (location) that you specify. Time formats that begin with an asterisk (*) respond to changes in regional date and time settings that are specified in Control Panel. Formats without an asterisk are not affected by Control Panel settings. |
Percentage |
Multiplies the cell value by 100 and displays the result with a percent (%) symbol. You can specify the number of decimal places that you want to use. |
Fraction |
Displays a number as a fraction, according to the type of fraction that you specify. |
Scientific |
Displays a number in exponential notation, replacing part of the number with E+n, where E (which stands for Exponent) multiplies the preceding number by 10 to the nth power. For example, a 2-decimal Scientific format displays 12345678901 as 1.23E+10, which is 1.23 times 10 to the 10th power. You can specify the number of decimal places that you want to use. |
Text |
Treats the content of a cell as text and displays the content exactly as you type it, even when you type numbers. |
Special |
Displays a number as a postal code (ZIP Code), phone number, or Social Security number. |
Custom |
Allows you to modify a copy of an existing number format code. Use this format to create a custom number format that is added to the list of number format codes. You can add between 200 and 250 custom number formats, depending on the language version of Excel that is installed on your computer. For more information about custom formats, see Create or delete a custom number format. |
You can apply different formats to numbers to change how they appear. The formats only change how the numbers are displayed and don’t affect the values. For example, if you want a number to show as currency, you’d click the cell with the number value > Currency.
Applying a number format only changes how the number is displayed and doesn’t affect cell values that’s used to perform calculations. You can see the actual value in the formula bar.
Here’s a list of available number formats and how you can use them in Excel for the web:
Number format |
Description |
---|---|
General |
Default number format. If the cell isn’t wide enough to show the entire number, this format rounds the number. For example, 25.76 shows as 26. Also, if the number is 12 or more digits, General format displays the value with scientific (exponential) notation.
|
Number |
Works very much like the General format but varies how it shows numbers with decimal place separators and negative numbers. Here are some examples of how both formats display numbers:
|
Currency |
Shows a monetary symbol with numbers. You can specify the number of decimal places with Increase Decimal or Decrease Decimal.
|
Accounting |
Also used for monetary values, but aligns the currency symbols and decimal points of numbers in a column. |
Short Date |
Shows date in this format:
|
Long Date |
Shows month, day and year in this format:
|
Time |
Shows number date and time serial numbers as time values. |
Percentage |
Multiplies the cell value by 100 and displays the result with a percent (%) symbol. Use Increase Decimal or Decrease Decimal to specify the number of decimal places you want.
|
Fraction |
Shows the number as a fraction. For example, 0.5 displays as ½. |
Scientific |
Displays numbers in exponential notation, replacing part of the number with E+n, where E (Exponent) multiplies the preceding number by 10 to the nth power. For example, a 2-decimal Scientific format displays 12345678901 as 1.23E+10, which is 1.23 times 10 to the 10th power. To specify the number of decimal places you want to use, apply Increase Decimal or Decrease Decimal. |
Text |
Treats the cell value as text and displays it exactly as you type it, even when you type numbers. Learn more about formatting numbers as text. |
Introduction
Number formats control how numbers are displayed in Excel. The key benefit of number formats is that they change how a number looks without changing any data. They are a great way to save time in Excel because they perform a huge amount of formatting automatically. As a bonus, they make worksheets look more consistent and professional.
Video: What is a number format
What can you do with custom number formats?
Custom number formats can control the display of numbers, dates, times, fractions, percentages, and other numeric values. Using custom formats, you can do things like format dates to show month names only, format large numbers in millions or thousands, and display negative numbers in red.
Where can you use custom number formats?
Many areas in Excel support number formats. You can use them in tables, charts, pivot tables, formulas, and directly on the worksheet.
- Worksheet — format cells dialog
- Pivot Tables — via value field settings
- Charts — data labels and axis options
- Formulas — via the TEXT function
What is a number format?
A number format is a special code to control how a value is displayed in Excel. For example, the table below shows 7 different number formats applied to the same date, January 1, 2019:
Input | Code | Result |
---|---|---|
1-Jan-2019 | yyyy | 2019 |
1-Jan-2019 | yy | 19 |
1-Jan-2019 | mmm | Jan |
1-Jan-2019 | mmmm | January |
1-Jan-2019 | d | 1 |
1-Jan-2019 | ddd | Tue |
1-Jan-2019 | dddd | Tuesday |
The key thing to understand is that number formats change the way numeric values are displayed, but they do not change the actual values.
Where can you find number formats?
On the home tab of the ribbon, you’ll find a menu of build-in number formats. Below this menu to the right, there is a small button to access all number formats, including custom formats:
This button opens the Format Cells dialog box. You’ll find a complete list of number formats, organized by category, on the Number tab:
Note: you can open Format Cells dialog box with the keyboard shortcut Control + 1.
General is default
By default, cells start with the General format applied. The display of numbers using the General number format is somewhat «fluid». Excel will display as many decimal places as space allows, and will round decimals and use scientific number format when space is limited. The screen below shows the same values in column B and D, but D is narrower and Excel makes adjustments on the fly.
How to change number formats
You can select standard number formats (General, Number, Currency, Accounting, Short Date, Long Date, Time, Percentage, Fraction, Scientific, Text) on the home tab of the ribbon using the Number Format menu.
Note: As you enter data, Excel will sometimes change number formats automatically. For example if you enter a valid date, Excel will change to «Date» format. If you enter a percentage like 5%, Excel will change to Percentage, and so on.
Shortcuts for number formats
Excel provides a number of keyboard shortcuts for some common formats:
Format | Shortcut |
---|---|
General format | Ctrl Shift ~ |
Currency format | Ctrl Shift $ |
Percentage format | Ctrl Shift % |
Scientific format | Ctrl Shift ^ |
Date format | Ctrl Shift # |
Time format | Ctrl Shift @ |
Custom formats | Control + 1 |
See also: 222 Excel Shortcuts for Windows and Mac
Where to enter custom formats
At the bottom of the predefined formats, you’ll see a category called custom. The Custom category shows a list of codes you can use for custom number formats, along with an input area to enter codes manually in various combinations.
When you select a code from the list, you’ll see it appear in the Type input box. Here you can modify existing custom code, or to enter your own codes from scratch. Excel will show a small preview of the code applied to the first selected value above the input area.
Note: Custom number formats live in a workbook, not in Excel generally. If you copy a value formatted with a custom format from one workbook to another, the custom number format will be transferred into the workbook along with the value.
How to create a custom number format
To create custom number format follow this simple 4-step process:
- Select cell(s) with values you want to format
- Control + 1 > Numbers > Custom
- Enter codes and watch preview area to see result
- Press OK to save and apply
Tip: if you want base your custom format on an existing format, first apply the base format, then click the «Custom» category and edit codes as you like.
How to edit a custom number format
You can’t really edit a custom number format per se. When you change an existing custom number format, a new format is created and will appear in the list in the Custom category. You can use the Delete button to delete custom formats you no longer need.
Warning: there is no «undo» after deleting a custom number format!
Structure and Reference
Excel custom number formats have a specific structure. Each number format can have up to four sections, separated with semi-colons as follows:
This structure can make custom number formats look overwhelmingly complex. To read a custom number format, learn to spot the semi-colons and mentally parse the code into these sections:
- Positive values
- Negative values
- Zero values
- Text values
Not all sections required
Although a number format can include up to four sections, only one section is required. By default, the first section applies to positive numbers, the second section applies to negative numbers, the third section applies to zero values, and the fourth section applies to text.
- When only one format is provided, Excel will use that format for all values.
- If you provide a number format with just two sections, the first section is used for positive numbers and zeros, and the second section is used for negative numbers.
- To skip a section, include a semi-colon in the proper location, but don’t specify a format code.
Characters that display natively
Some characters appear normally in a number format, while others require special handling. The following characters can be used without any special handling:
Character | Comment |
---|---|
$ | Dollar |
+- | Plus, minus |
() | Parentheses |
{} | Curly braces |
<> | Less than, greater than |
= | Equal |
: | Colon |
^ | Caret |
‘ | Apostrophe |
/ | Forward slash |
! | Exclamation point |
& | Ampersand |
~ | Tilde |
Space character |
Escaping characters
Some characters won’t work correctly in a custom number format without being escaped. For example, the asterisk (*), hash (#), and percent (%) characters can’t be used directly in a custom number format – they won’t appear in the result. The escape character in custom number formats is the backslash (). By placing the backslash before the character, you can use them in custom number formats:
Value | Code | Result |
---|---|---|
100 | #0 | #100 |
100 | *0 | *100 |
100 | %0 | %100 |
Placeholders
Certain characters have special meaning in custom number format codes. The following characters are key building blocks:
Character | Purpose |
---|---|
0 | Display insignificant zeros |
# | Display significant digits |
? | Display aligned decimals |
. | Decimal point |
, | Thousands separator |
* | Repeat following character |
_ | Add space |
@ | Placeholder for text |
Zero (0) is used to force the display of insignificant zeros when a number has fewer digits than zeros in the format. For example, the custom format 0.00 will display zero as 0.00, 1.1 as 1.10 and .5 as 0.50.
Pound sign (#) is a placeholder for optional digits. When a number has fewer digits than # symbols in the format, nothing will be displayed. For example, the custom format #.## will display 1.15 as 1.15 and 1.1 as 1.1.
Question mark (?) is used to align digits. When a question mark occupies a place not needed in a number, a space will be added to maintain visual alignment.
Period (.) is a placeholder for the decimal point in a number. When a period is used in a custom number format, it will always be displayed, regardless of whether the number contains decimal values.
Comma (,) is a placeholder for the thousands separators in the number being displayed. It can be used to define the behavior of digits in relation to the thousands or millions digits.
Asterisk (*) is used to repeat characters. The character immediately following an asterisk will be repeated to fill remaining space in a cell.
Underscore (_) is used to add space in a number format. The character immediately following an underscore character controls how much space to add. A common use of the underscore character is to add space to align positive and negative values when a number format is adding parentheses to negative numbers only. For example, the number format «0_);(0)» is adding a bit of space to the right of positive numbers so that they stay aligned with negative numbers, which are enclosed in parentheses.
At (@) — placeholder for text. For example, the following number format will display text values in blue:
0;0;0;[Blue]@
See below for more information about using color.
Automatic rounding
It’s important to understand that Excel will perform «visual rounding» with all custom number formats. When a number has more digits than placeholders on the right side of the decimal point, the number is rounded to the number of placeholders. When a number has more digits than placeholders on the left side of the decimal point, extra digits are displayed. This is a visual effect only; actual values are not modified.
Number formats for TEXT
To display both text along with numbers, enclose the text in double quotes («»). You can use this approach to append or prepend text strings in a custom number format, as shown in the table below.
Value | Code | Result |
---|---|---|
10 | General» units» | 10 units |
10 | 0.0″ units» | 10.0 units |
5.5 | 0.0″ feet» | 5.5 feet |
30000 | 0″ feet» | 30000 feet |
95.2 | «Score: «0.0 | Score: 95.2 |
1-Jun | «Date: «mmmm d | Date: June 1 |
Number formats for DATES
Dates in Excel are just numbers, so you can use custom number formats to change the way they display. Excel has many specific codes you can use to display components of a date in different ways. The screen below shows how Excel displays the date in D5, September 3, 2018, with a variety of custom number formats:
Number formats for TIME
Times in Excel are fractional parts of a day. For example, 12:00 PM is 0.5, and 6:00 PM is 0.75. You can use the following codes in custom time formats to display components of a time in different ways. The screen below shows how Excel displays the time in D5, 9:35:07 AM, with a variety of custom number formats:
Note: m and mm can’t be used alone in a custom number format since they conflict with the month number code in date format codes.
Number formats for ELAPSED TIME
Elapsed time is a special case and needs special handling. By using square brackets, Excel provides a special way to display elapsed hours, minutes, and seconds. The following screen shows how Excel displays elapsed time based on the value in D5, which represents 1.25 days:
Number formats for COLORS
Excel provides basic support for colors in custom number formats. The following 8 colors can be specified by name in a number format: [black] [white] [red][green] [blue] [yellow] [magenta] [cyan]. Color names must appear in brackets.
Colors by index
In addition to color names, it’s also possible to specify colors by an index number (Color1,Color2,Color3, etc.) The examples below are using the custom number format: [ColorX]0″▲▼», where X is a number between 1-56:
[Color1]0"▲▼" // black
[Color2]0"▲▼" // white
[Color3]0"▲▼" // red
[Color4]0"▲▼" // green
etc.
The triangle symbols have been added only to make the colors easier to see. The first image shows all 56 colors on a standard white background. The second image shows the same colors on a gray background. Note the first 8 colors shown correspond to the named color list above.
Apply number formats in a formula
Although most number formats are applied directly to cells in a worksheet, you can also apply number formats inside a formula with the TEXT function. For example, with a valid date in A1, the following formula will display the month name only:
=TEXT(A1,"mmmm")
The result of the TEXT function is always text, so you are free to concatenate the result of TEXT to other strings:
="The contract expires in "&TEXT(A1,"mmmm")
The screen below shows the number formats in column C being applied to numbers in column B using the TEXT function:
One quirk of the TEXT function relates to double quotes («») that are part of certain custom number formats. Because the format_text is entered as a text string, Excel won’t allow you to enter the formula without removing the quotes or adding more quotes. For example, to display a large number in thousands, you can use a custom number format like this:
0, "k"
Notice k appears in quotes («k»). To apply the same format with the TEXT function, you can use simply:
=TEXT(A1,"0, k")
Notice the k is not surrounded by quotes. Alternately, you can add extra double quotes as below, which returns the same result:
=TEXT(A1,"0,""K""")
This behavior only occurs when you are hardcoding a format inside TEXT. If you are applying a format entered elsewhere on the worksheet (as in cells C6 and C9 in the worksheet above) you can use a standard number format.
Measurements
You can use a custom number format to display numbers with an inches mark («) or a feet mark (‘). In the screen below, the number formats used for inches and feet are:
0.00 ' // feet
0.00 " // inches
These results are simplistic, and can’t be combined in a single number format. You can however use a formula to display feet together with inches.
Conditionals
Custom number formats also up to two conditions, which are written in square brackets like [>100] or [<=100]. When you use conditionals in custom number formats, you override the standard [positive];[negative];[zero];[text] structure. For example, to display values below 100 in red, you can use:
[Red][<100]0;0
To display values greater than or equal to 100 in blue, you can extend the format like this:
[Red][<100]0;[Blue][>=100]0
To apply more than two conditions, or to change other cell attributes, like fill color, etc. you’ll need to switch to Conditional Formatting, which can apply formatting with much more power and flexibility using formulas.
Plural text labels
You can use conditionals to add an «s» to labels greater than zero with a custom format like this:
[=1]0″ day»;0″ days»
Telephone numbers
Custom number formats can also be used for telephone numbers, as shown in the screen below:
Notice the third and fourth examples use a conditional format to check for numbers that contain an area code. If you have data that contains phone numbers with hard-coded punctuation (parentheses, hyphens, etc.) you will need to clean the telephone numbers first so that they only contain numbers.
Hide all content
You can actually use a custom number format to hide all content in a cell. The code is simply three semi-colons and nothing else ;;;
To reveal the content again, you can use the keyboard shortcut Control + Shift + ~, which applies the General format.
Other resources
- Developer Bryan Braun built a nice interactive tool for building custom number formats
If you used Excel in any shape or form, there is a pretty good chance that you’ve used the formatting and number formatting features. Formatting options like number, currency, percentage, date and time values are easily accessible to users. However, that’s not all there is in the world of text and number formatting. Going down the rabbit hole, custom formatting can help you fully configure Excel’s built-in settings for formatting.
The main advantage of this approach is that you can alter the look of your data without changing the actual values. This means that you do not need to use additional spaces or formulas to create the layout you want and preserve the raw data.
If you want to modify your data anyways, or need to change a value inside a formula, you can use the TEXT function with all custom formatting syntax we are going to cover in this article. It should be noted that the TEXT function returns a text, and the return value cannot be used in mathematical calculations. If you do, you will receive a #VALUE! error. In this article we’re going to be using a workbook template. You can download it below.
How to create a custom number format in Excel
- Select the cell to be formatted and press Ctrl+1 to open the Format Cells dialog. An alternative way to do is by right-clicking the cell and then going to Format Cells > Number Tab.
- Under Category, select Custom.
- Type in the format code into the Type
- Click OK to save your changes.
Note: In Format Cells dialog you can modify the built-in format codes by selecting the format you want to modify in its own category (i.e. Currency > ($1,234.10)) and then selecting Custom Category. Don’t worry, Excel will not let you delete built-in formats.
Basics
Syntax
The format code has 4 sections separated by semicolons.
POSITIVE; NEGATIVE; ZERO; TEXT
These sections are optional,
- If a code contains only 1 section, the format is applied to all number types — positive, negative and zero.
- If a code contains 2 sections, the first section is used for positive and zero values, while the second section is applied to negative values.
- If a code contains 3 sections, the first is for positive, the second is for negative, and the third is for zero.
- A code only affects text values if all sections exist.
Default format type in Excel is called General. You can type General for sections you don’t want formatted. Make sure you use a minus sign (-) with General if you want to skip negative values.
If you want to completely hide a type, leave it blank after the semicolon. For example; to hide 0 values, General;-General;;General
Placeholders and the Cheat Sheet
Placeholder | Description | Raw Value | Format Code | Formatted Value |
General | Default format | 1234.567 | General | 1234.567 |
# | Placeholder for digits (numbers) and does not add any leading zeroes. | 1234.567 | #####.#### | 1234.567 |
0 | Placeholder for digits (numbers) and add any leading zeroes. | 1234.567 | 00000.0000 | 01234.5670 |
? | Placeholder for digits (numbers) and add space characters. | 1234.567 | ?????.???? | 1234.567 |
. | Placeholder for the decimal place. | 1234.567 | 0.00 | 1234.57 |
_ | Adds a blank space, to the width of the following character. You can use in combination with parentheses to add left and right indents, _( and _) respectively. | 99 | _(#_);(#) | 99 |
-25 | (25) | |||
58 | 58 | |||
12 | 12 | |||
-71 | (71) | |||
36 | 36 | |||
* | Repeats the character after asterisk until the width of the cell is filled. | 66 | 0 *! | 66 !!!!!!!!!!!!!!! |
Full Name | @ *_ | Full Name ____ | ||
% | Convert value to a percentage with % sign | 0.12 | % | 12% |
, | Thousands separator | 1234.567 | #, | 1 |
12345678 | #, | 12,346 | ||
12345678 | #,###, | 12,346 | ||
12345678 | #,, | 12 | ||
E | Scientific notation format. Requires a ‘+’ symbol after, and a digit placeholder before and after. | 1234.567 | 0.00E+00 | 1.23E+03 |
/ | Represents fractions | 1.234 | # ##/## | 1 11/47 |
1.234 | # 000/000 | 1 117/500 | ||
1.234 | ##/## | 58/47 | ||
«» | Text placeholder for multiple characters | 1234.567 | #,##0 «km/h» | 1,235 km/h |
Good | «Result is: «@ | Result is: Good | ||
Text placeholder for single character | 1234 | #.00, K | 1.23 K | |
1234567 | #.00,, M | 1.23 M | ||
@ | Placeholder for text | Bad | «Result is: «@ | Result is: Bad |
[color] | Change Color of value. Options: [Black], [Green], [White], [Blue], [Magenta], [Yellow], [Cyan], [Red] | 1234.567 | [Green]#,##0.00_); [Red](#,##0.00); [Blue]0.00_); [Magenta]@ |
1,234.57 |
-1234.567 | (1,234.57) | |||
0 | 0.00 | |||
This is a text | This is a text |
Common Practices
Display and control of the first digit and decimals
Decimal places in the code are indicated with a period (.). Number of zeroes after the period (.) define the number of decimal places. For example,
- 0 — display 1 decimal place
- 00 — display 2 decimal places
If the number has more decimals than the decimal placeholders defined, the number will be rounded to the nearest number of placeholders.
Raw Value | Format Code | Formatted Value |
123.4 | 0.0 | 123.4 |
123.4 | 0.00 | 123.40 |
123.45 | 0.00 | 123.45 |
123.45 | 0.00 | 123.46 |
123.456 | 0.0 | 123.5 |
Alternatively, hash (#) and question mark (?) symbols can be used as decimal places. However, because any missing decimal places will be filled with zeroes, using zeroes instead will be easier to read.
Raw Value | Format Code | Formatted Value |
0.25 | 0.00 | 0.25 |
0.25 | #.## | .25 |
123 | 0.00 | 123.0 |
123 | #.?? | 123.00 |
123 | #.## | 123. |
Add text to numbers
Custom text can be added to the beginning or the end of a value. Text and characters should be added inside quotes («») and backslashes (). You can use backslash () to add single character.
Raw Value | Format Code | Formatted Value |
123.4 | 0.0 «ft.» | 123.4 ft. |
123.4 | 0.00 l | 123.40 l |
123.45 | «Approx.» 0 | Approx. 123 |
123.45 | «Result:» 0.00 C | Result: 123.46 C |
Bad | «Result is: «@ | Result is: Bad |
Quotation marks or backslashes are not necessary for spaces ( ) and some special characters.
Symbol | Description |
+ and — | Plus and minus signs |
( ) | Left and right parenthesis |
: | Colon |
^ | Caret |
‘ | Apostrophe |
{ } | Curly brackets |
< > | Less-than and greater than signs |
= | Equal sign |
/ | Forward slash |
! | Exclamation point |
& | Ampersand |
~ | Tilde |
Space character |
Below are some special characters you can use by copying or typing in the numerical code while pressing down Alt button.
Symbol | Code | Description |
™ | Alt+0153 | Trademark |
© | Alt+0169 | Copyright symbol |
° | Alt+0176 | Degree symbol |
± | Alt+0177 | Plus-Minus sign |
µ | Alt+0181 | Micro sign |
Hide value
If you leave any number of sections blank, the value of those sections will be hidden. A section should always be separated (defined) by a semicolon (;). Here are some examples,
Raw Value | Format Code | Formatted Value |
1 | 0;;0; | 1 |
-2 | 0;;0; | |
0 | 0;;0; | 0 |
Some text | 0;;0; | |
1 | ;(0);;@ | |
-2 | ;(0);;@ | (2) |
0 | ;(0);;@ | |
Some text | ;(0);;@ | Some Text |
1 | ;;; | |
-2 | ;;; | |
0 | ;;; | |
Some text | ;;; |
Replace zeroes with dashes
Zeroes can make data tables look more complicated than they actually are. You can hide them completely by using the previous method, or replace them with any character of your choice. Dash (-) is a common example. All you need to is place a dash into the ‘Zero section’.
Raw Value | Format Code | Formatted Value |
0 | General;-General;»-«;General | — |
3487 | General;-General;»-«;»-« | — |
12 | #,##0.00;(#,##0.00);»-«; | — |
Start with zeroes
If try to enter a ZIP number that starts with 0, the leading zeroes will be removed automatically by Excel. To keep the leading zeros, use zero (0) placeholder for whole numbers.
Raw Value | Format Code | Formatted Value |
10010 | 00000 | 10010 |
3487 | 00000 | 03487 |
12 | 00000 | 00012 |
0 | 00000 | 00000 |
123456 | 00000 | 123456 |
Dealing with thousands, millions, and more
You may have noticed that ‘0.0’ or other simple formats do not separate thousands or millions. Adding a comma into the code will insert commas to separate numbers.
Raw Value | Format Code | Formatted Value |
1234 | #,##0 | 1,234 |
123456 | #,##0 | 123,456 |
12345678 | #,##0 | 12,345,678 |
123456.789 | #,##0 | 123,457 |
123456.789 | #,##0.0 | 123,456.8 |
There must be placeholders for numbers smaller than one thousand, otherwise such values will be hidden. This behavior allows us to round and format our value to show only thousands or millions.
Raw Value | Format Code | Formatted Value |
1234 | #, | 1 |
123456 | #, | 123 |
12345678 | #, | 12345 |
12345678 | #,, | 12 |
123456 | #.0, K | 123.5 K |
12345678 | #.0,, M | 12.3 M |
Display numbers as phone numbers
Phone numbers can be hard to read without any separators. Custom Number Format Codes is perfect for this job. The hash (#) character should be your best bet to avoid any redundancy of placeholders (0, ?)
Raw Value | Format Code | Formatted Value |
1234567890 | (###) ###-#### | (123) 456-7890 |
12345678900 | (###) #### #### | (123) 4567 8900 |
1234567890 | (##) #### #### | (12) 3456 7890 |
Showing Month and Weekday Names
Date and time values are stored as numbers in Excel. When you enter a date, Excel automatically converts it into a numerical value, and then formats the cell.
Before jumping into the code, let’s review some basics. Formatting code has special placeholders for date and time formatting that behave a bit differently. For example, while m and mm will show month as a number, mmm and mmmm will show as a text string. Below are some examples.
Raw Value | Format Code | Formatted Value |
4/1/2018 | m | 4 |
4/1/2018 | mm | 04 |
4/1/2018 | mmm | Apr |
4/1/2018 | mmmm | April |
4/1/2018 | mmmmm | A |
4/1/2018 | d | 1 |
4/1/2018 | dd | 01 |
4/1/2018 | ddd | Sun |
4/1/2018 | dddd | Sunday |
4/1/2018 11:59:31 PM | dddd, mmmm dd, yyyy h:mm AM/PM;@ | Sunday, April 01, 2018 11:59 PM |
Here is the full list of options for the date 4/1/2018 23:59:31 ,
Format Code | Description | Example (4/1/2018 23:59:31) |
yyyy | Displays the year as a four-digit number. | 2018 |
yy | Displays the year as a two-digit number. | 18 |
m | Displays the month as a number without a leading zero. | 4 |
mm | Displays the month with a leading zero. | 04 |
mmm | Displays the month as text, as an abbreviation. | Apr |
mmmm | Displays the month as text. | April |
mmmmm | Displays the month as a single character | A |
d | Displays the day as a number, without a leading zero. | 1 |
dd | Displays the day as a number, with a leading zero. | 01 |
ddd | Displays the day as a day of the week, as an abbreviation. | Sun |
dddd | Displays the day as a day of the week, without abbreviation | Sunday |
h | Displays the hour without a leading zero. | 23 |
hh | Displays the hour with a leading zero. | 23 |
[h] | Displays elapsed time in hours (to be used when the time value exceeds 24 hours). | 1036607 |
m | Displays the minute without a leading zero. | 4 |
mm | Displays the minute with a leading zero. | 04 |
[m] | Displays elapsed time in minutes (to be used when the time value exceeds 60 minutes). | 62196479 |
s | Displays the second without a leading zero. | 31 |
ss | with a leading zero. | 31 |
[s] | Displays elapsed time in seconds (to be used when the time value exceeds 60 seconds). | 3731788771 |
AM/PM | Converts to 12-hour time. Displays either AM/am/A/a or PM/pm/P/p depending on the time of day. | PM |
am/pm | pm | |
A/P | P | |
a/p | p |
Come in Colors Everywhere
Number Formatting can be used color sections of a code. A common example is using the color red for negative numbers. Color code must be placed inside square brackets (i.e. [color]), and entered at the beginning of a section. Here are some available colors,
- [Black]
- [Blue]
- [Cyan]
- [Green]
- [Magenta]
- [Red]
- [White]
- [Yellow]
Raw Value | Format Code | Formatted Value |
1234.567 | [Green]#,##0.00_);[Red](#,##0.00);[Blue]0.00);[Magenta]@ | 1,234.57 |
-1234.567 | (1,234.57) | |
0 | 0.00 | |
This is a text | This is a text |
Conditions
Although Excel has conditional formatting menu, basic conditions can be applied through code. Condition should be placed inside square brackets (i.e. [condition]) just like colors. Conditions are similar to the conditions in some functions (i.e. SUMIF). First add a logical operator, and then a value. For example, “[>=1000000]” means “if value of cell is greater than or equal to 1,000,000 apply the following format”. Conditions should come before the actual code, again, just like with colors. If you want to a color as well, the color code should come first.
Another important thing to note here is, that section structure changes from Positive, Negative, Zero, Text to First Condition, Second Condition (if exists), if previous conditions are not applied. There should be at least two sections for conditions.
If you enter only one condition code and then save the format, Excel will automatically add the second section with «;General». This means that if the condition is not met, General format will be used.
Raw Value | Format Code | Formatted Value |
1234567890 | [>=1000000]#,##0,,»M»;[>=1000]#,##0,»K»;0 | 1,235M |
12345 | 12K | |
1 | [=1]0″ apple»;0″ apples» | 1 apple |
10 | 10 apples | |
25 | [Green][>=85]»PASSED»;[Blue][>=60]»RE-CHECK»;[Red]»FAILED» | FAILED |
72 | RE-CHECK | |
91 | PASSED |
In Excel, you aren’t limited to using built-in number formats. You can define your own custom number formats to display values as thousands or millions (23K or 95.3M), add leading zeros, display » — » for zero values, make negative values red, add bullets, and much more.
This Article (bookmarks):
- Watch the Video Overview
- How to Create a Custom Number Format
- Number Format Codes
- Examples
- Format for Thousands and Millions
- Display Leading Zeros and Include Commas
- Display Units Without Converting to Text
- Special Time Formats
- Including Special Symbols
- Displaying Fractions
- Trailing and Leading Characters to Fill a Cell
- Chart Axes and Labels
- Using Color Codes
- Conditional Operators
- Custom Location Codes for Dates
Watch the video we created to go along with this article!
How to Create a Custom Number Format
To create a custom number format, it is easiest to begin with a built-in format. Open the Format Cells dialog box by pressing Ctrl+1 (or right-click on a cell and select Format Cells) and select the Number tab (see the image below). Then (1) Choose Custom from the Category list, (2) Select a built-in format similar to what you want, and (3) Edit the format string in the Type field.
Number Format Codes
A number format string uses up to 4 different codes, separated by semicolons, as shown in the image below.
Instead of explaining the syntax in detail at this point, let’s take a look at some examples and learn as we go.
Some of the characters like #, 0, @, etc. have special meanings. Some codes like [Red] can change the font color, and quotes can be used to display text or special characters. The table below summarizes some of these special characters.
Special Characters in Number Formats
Character | Description |
---|---|
# | A digit placeholder |
0 | A digit that is to be displayed even if it is zero |
, | (Comma) Interpreted as a 1000’s marker |
@ | Represents the value displayed as text |
* | (Asterisk) Repeats the next character to fill the cell |
[ColorCode] | See the section below about using color codes |
[<=100] | Conditional operators (valid only in the Positive and Negative sections) |
/ | Used for fractions such as # #/12 or as the / character for dates |
» « | (Quotes) Used to display whatever is contained within the quotes as text, such as 0.00 «feet» |
d or dd ddd dddd |
Day number (0-31 or 00-31) Abbreviated day of week (Mon, Tue, etc.) Full day of week (Monday, Tuesday, etc.) |
m or mm mmm mmmm mmmmm |
Month number (0-12 or 00-12) Abbreviated month name (Jan, Feb, etc.) Full month name (January, February, etc.) First letter of the month (J, F, M, etc.) |
y or yy yyyy |
Year (0-99 or 00-99) Full year (1900-9999) |
h or hh m or mm s or ss |
Hour (0-23 or 00-23) Minutes (0-59 or 00-59) Seconds (0-59 or 00-59) |
NOTE Some characters are specific to locale/language settings. For example J is used for Year in some countries.
Custom Number Format Examples
The examples below show some of the custom number formats that I’ve found the most useful. This isn’t a comprehensive list of all possible number formats. See support.microsoft.com to search for other articles on this subject.
TIP Using a custom number format only affects the displayed value. A formula that references the cell will use the stored value no matter how it is displayed. This means you can still use a formula to refer to the value even though the number might be displayed as «12 ft.»
To see these examples in action, download the Excel file below.
Download the Example File (CustomNumberFormats.xlsx)
Custom Number Format for Thousands and Millions
Format Code | Value | Displayed As | Description |
---|---|---|---|
0,K 0.0,K 0.0, «Thousand» |
23543 | 24K 23.5K 23.5 Thousand |
Display values in thousands, using the letter K to indicate thousands. The «K» is just a displayed character — it has no special meaning in the number format string. If you want to display more than one letter, you need to enclose the characters in quotes, like the «Thousand» example. |
0,,»M» 0.0,,»M» 0.0,, «Million» |
23543000 | 24M 23.5M 23.5 Million |
Display values in millons, using the letter M to indicate millions. Note that in this case, you need two commas. |
NOTE These are very useful for chart axes and labels.
Display Leading Zeros and Include Commas
Format Code | Value | Displayed As | Description |
---|---|---|---|
000 00000 |
50.8 | 051 00051 |
Display values with leading zeros. This does not convert the value to text — it is only a display format. |
#,##0.0 | 3543.46 | 3,543.5 | Display values using commas to separate thousands, millions, etc. The # sign is used as a placeholder, meaning that if there are no 10’s, 100’s, or 1000’s, don’t display them. |
Display Units Without Converting to Text
Format Code | Value | Displayed As |
---|---|---|
• Display a number and text in the same cell using the conditions [=1] and [>1]. The value is stored as a number, so you can still do calculations on the number of people. | ||
[=1]# «person»;[>1]# «people»;0 | 1 5 0 |
1 person 5 people 0 |
• Display a number and text in the same cell. The value is stored as a number, so you can still do calculations. | ||
0.0 «ft» 0.0 «kg» # #/## «in» |
2.2 4.5 6.25 |
2.2 ft 4.5 kg 6 1/4 in |
• Display a numeric YYMMDD value in years, months, days. | ||
##»y» ##»m» ##»d» | 360712 | 36y 07m 12d |
Special Time Formats
There are quite a few built-in time formats to choose from. The following may be less known.
Format Code | Value | Displayed As | Description |
---|---|---|---|
[h]:mm:ss [h]:mm [mm]:ss [ss] |
49:03:47 | 49:03:47 49:03 2943:47 176627 |
Shows elapsed time in hours, minutes or seconds. Note that time does not round up. |
h:mm A/P h:mm a/p |
2:25 PM | 2:25 P 2:25 p |
Displays time using «a» for AM and «p» for PM. Useful when trying to minimize column widths without making fonts smaller. |
Including Special Symbols
Some ascii and unicode characters can be copied and pasted directly into the format code. This can be handy for displaying the degrees symbol for temperatures as well as other tricks like showing up and down arrows or bulleted lists.
Format Code | Value | Displayed As | Description |
---|---|---|---|
#.#»°» | 98.7 | 98.7° | Display temperature in degrees with the ° symbol. |
[Color10]▲0;[Red]▼-0 | 5 -5 |
▲5 ▼-5 |
Display special symbols for positive and negative, combined with colors. |
;;;»•» @ | Eggs Bacon |
• Eggs • Bacon |
Create a bulleted list using a special symbol for the bullet. When you enter text, the bullet will be displayed. Numbers and zero values will not be displayed. |
Displaying Fractions
Format Code | Value | Displayed As | Description |
---|---|---|---|
# ??/12 | 5.75 12.5 |
5 9/12 12 6/12 |
Display a decimal number of feet as feet and inches (rounded to the nearest inch). Or display a decimal year in terms of years and months. |
# ??/100 | 5.2 5.05 12.81 |
5 20/100 5 5/100 12 81/100 |
Using ??/100 will help line up values in a column (as opposed to just using ?/100). Note that fractions are automatically rounded. |
?/2 | 5.2 | 10/2 | Displays a simple fraction as numerator/denominator. |
Trailing and Leading Characters to Fill a Cell
The asterisk (*) in a format code repeats the following character to fill the width of the cell.
Format Code | Value | Displayed As | Description |
---|---|---|---|
— @ *- | ✁ | — ✁ —————- | Trailing characters. |
*.@ | pg 2 | ………………pg 2 | Leading characters |
Custom Number Formats for Chart Axes and Labels
Format Code | Value | Displayed As | Description |
---|---|---|---|
0 «AD»;0 «BC» | 247 -600 |
247 AD 600 BC |
AD and BC Years. Use negative numbers for BC years and positive numbers for AD years. |
mmm{Ctrl+j}yyyy | 8/20/18 | Aug 2018 |
Add a Carriage Return within the custom number format (e.g. between dddd and mmm) by pressing Ctrl+j. |
[Color10]▲0.0%;[Red]▼-0.0% | 15.23% -23.57% |
▲15.2% ▼-23.6% |
Display arrows for positive and negative, combined with colors and percentages. |
A couple of these examples can be seen in the image below. However, notice that the data labels don’t use color codes, so the percentages are shown only as black text rather than red and green. Too bad. Maybe Microsoft will fix that some day.
NOTE Editing a custom number format that contains a carriage return is tricky because you can’t see the second row. This is why I write out the code first using «{Ctrl+j}» or just «{j}» and then delete the «{j}» and press Ctrl+j in its place.
When adding a custom number format using the Format Axis window pane, you may not be able to press Ctrl+j to add a carriage return. In that case, first edit the format of the data source, then click on the Link to Source box as shown in the image to the right. After doing that, you can uncheck the Link to Source box and modify the original data source formatting.
Other Tricks
Format Code | Value | Displayed As | Description |
---|---|---|---|
;;; | anything | Display nothing, regardless of the value. | |
0.# | 2 | 2. | Display a decimal point without a 0 after the decimal (2. instead of 2.0) |
???.??? | 1.2 12.3 123.456 |
1.2 12.3 123.456 |
Vertically align the decimal point when displaying a column of numbers. |
NOTE If you are looking for format codes for phone numbers, social security numbers, or zip codes, look in the Special category within the list of built-in number formats.
Custom Number Format Color Codes
By using color format codes such as [Red] or [Blue] or [Color10], you have a limited ability to alter the color of the font via custom number formats. The most common use I’ve seen is to color negative values red. However, one of the examples above also shows how you might want to use a green arrow.
Even though a new color palette was introduced in Excel 2007, the color codes for custom number formats are still based on the old color palette for the Excel 97-2003 format. I created the graphic below to provide a quick reference.
I made the above color code reference match the layout of the old color palette because there is not a consistent pattern to the numbering.
Define Your Own Color: You can modify the color palette in newer versions of Excel by going to File > Options > Save > Colors. This allows you to change the color associated with the Color1 through Color56 codes. This means that Color10 might not always be a dark green. If you purposely change the color palette (or somebody else does), Color10 might be some other color.
Excel 2016: File > Options > Save > Colors
NOTE The Color1-56 codes in Google Sheets are fixed colors and aren’t changed when you upload an Excel file with a customized color palette.
Conditional Operators
Conditional operators such as [<100] can be used to change the formatting in cases where positive;negative;0 is not how you want the divisions defined.
For example, the following format will display numbers less than 10 red, numbers between 10 and 20 green, other numbers blue, and text will be displayed based on the cell’s font color: [Red][<10]0.00;[Green][<=20]0.00;[Blue]0.00;@
You are limited to 2 numeric conditions, which you place in the negative and positive sections of the format code.
Another use of conditional operators is to display phone numbers with and without an area code, depending on how many digits are in the phone number like this: [<=9999999]###-####;(###)###-####. This assumes that the phone numbers are entered as numbers and not text values. Meaning, that if you actually enter 123-1234 into a cell in Excel, it will be interpreted as a text value, not a number. The phone number format will display 1234567 to 123-4567 and it will display 1234567890 to (123)456-7890.
Custom Location Codes for Dates
When displaying month names and weekday names for dates, you can use location codes such as [$-fr-CA] at the beginning of the format code to tell Excel to display the names in other languages. To learn what the code is for a specific language and location, use the Format Cells dialog in Excel, choose one of the built-in Date formats, then choose the Locale (location) from the drop-down list. Then you can return to the Format Cells dialog box and click on the Custom tab to see what location code was added.
Format Code | Value | Displayed As | Language/Location |
---|---|---|---|
[$-en-US](ddd) mmm d, yyyy | 10/1/2018 | (Mon) Oct 1, 2018 | English (United States) |
[$-fr-CA](ddd) mmm d, yyyy | 8/1/2018 | (mer.) août 1, 2018 | French (Canada) |
[$-de-DE](ddd) mmm d, yyyy | 10/1/2018 | (Mo) Okt 1, 2018 | German (Germany) |
Other Notes About Custom Number Formats
To delete a custom number format, open the Format Cells dialog box, select the custom format from the list, then click Delete. When you delete a custom number format, all values in your workbook that use that format will revert to the General format.
Custom number formats that you create are saved with the file. If you want to use the custom format in a different file, you can copy/paste the formatting from your other file by copying and pasting the formatted cell or using the Format Painter tool.
References
- Number Formats for Charts by Jon Peltier, Excel MVP
- Excel Custom Number Format Guide by Mynda Treacy, Excel MVP