Excel number formatting codes

Excel for Microsoft 365 for Mac Excel 2021 for Mac Excel 2019 for Mac Excel 2016 for Mac Excel for Mac 2011 More…Less

You can use number formats to change the appearance of numbers, including dates and times, without changing the actual number. The number format does not affect the cell value that Excel uses to perform calculations. The actual value is displayed in the formula bar.

Excel provides several built-in number formats. You can use these built-in formats as is, or you can use them as a basis for creating your own custom number formats. When you create custom number formats, you can specify up to four sections of format code. These sections of code define the formats for positive numbers, negative numbers, zero values, and text, in that order. The sections of code must be separated by semicolons (;).

The following example shows the four types of format code sections.

Four types of format code sections

Callout 1Format for positive numbers

Format for negative numbers

Callout 3 Format for zeros

Callout 4 Format for text

If you specify only one section of format code, the code in that section is used for all numbers. If you specify two sections of format code, the first section of code is used for positive numbers and zeros, and the second section of code is used for negative numbers. When you skip code sections in your number format, you must include a semicolon for each of the missing sections of code. You can use the ampersand (&) text operator to join, or concatenate, two values.

Create a custom format code

  1. On the Home tab, click Number Format Format Number box, and then click More Number Formats.

  2. In the Format Cells dialog box, in the Category box, click Custom.

  3. In the Type list, select the number format that you want to customize.

    The number format that you select appears in the Type box at the top of the list.

  4. In the Type box, make the necessary changes to the selected number format.

Format code guidelines

To display both text and numbers in a cell, enclose the text characters in double quotation marks (» «) or precede a single character with a backslash (). Include the characters in the appropriate section of the format codes. For example, you could type the format $0.00″ Surplus»;$–0.00″ Shortage» to display a positive amount as «$125.74 Surplus» and a negative amount as «$–125.74 Shortage.»

You don’t have to use quotation marks to display the characters listed in the following table:

Character

Name

$

Dollar sign

+

Plus sign

Minus sign

/

Forward slash

(

Left parenthesis

)

Right parenthesis

:

Colon

!

Exclamation point

^

Circumflex accent (caret)

&

Ampersand

Apostrophe

~

Tilde

{

Left curly bracket

}

Right curly bracket

<

Less than sign

>

Greater than sign

=

Equal sign

Space character

To create a number format that includes text that is typed in a cell, insert an «at» sign (@) in the text section of the number format code section at the point where you want the typed text to be displayed in the cell. If the @ character is not included in the text section of the number format, any text that you type in the cell is not displayed; only numbers are displayed. You can also create a number format that combines specific text characters with the text that is typed in the cell. To do this, enter the specific text characters that you want before the @ character, after the @ character, or both. Then, enclose the text characters that you entered in double quotation marks (» «). For example, to include text before the text that’s typed in the cell, enter «gross receipts for «@ in the text section of the number format code.

To create a space that is the width of a character in a number format, insert an underscore (_) followed by the character. For example, if you want positive numbers to line up correctly with negative numbers that are enclosed in parentheses, insert an underscore at the end of the positive number format followed by a right parenthesis character.

To repeat a character in the number format so that the width of the number fills the column, precede the character with an asterisk (*) in the format code. For example, you can type 0*– to include enough dashes after a number to fill the cell, or you can type *0 before any format to include leading zeros.

You can use number format codes to control the display of digits before and after the decimal place. Use the number sign (#) if you want to display only the significant digits in a number. This sign does not allow the display non-significant zeros. Use the numerical character for zero (0) if you want to display non-significant zeros when a number might have fewer digits than have been specified in the format code. Use a question mark (?) if you want to add spaces for non-significant zeros on either side of the decimal point so that the decimal points align when they are formatted with a fixed-width font, such as Courier New. You can also use the question mark (?) to display fractions that have varying numbers of digits in the numerator and denominator.

If a number has more digits to the left of the decimal point than there are placeholders in the format code, the extra digits are displayed in the cell. However, if a number has more digits to the right of the decimal point than there are placeholders in the format code, the number is rounded off to the same number of decimal places as there are placeholders. If the format code contains only number signs (#) to the left of the decimal point, numbers with a value of less than 1 begin with the decimal point, not with a zero followed by a decimal point.

To display

As

Use this code

1234.59

1234.6

####.#

8.9

8.900

#.000

.631

0.6

0.#

12

1234.568

12.0

1234.57

#.0#

Number:

44.398

102.65

2.8

Decimal points aligned:

  44.398

102.65

    2.8

???.???

Number:

5.25

5.3

Numerators of fractions aligned:

5 1/4

5 3/10

# ???/???

To display a comma as a thousands separator or to scale a number by a multiple of 1000, include a comma (,) in the code for the number format.

To display

As

Use this code

12000

12,000

#,###

12000

12

#,

12200000

12.2

0.0,,

To display leading and trailing zeros prior to or after a whole number, use the codes in the following table.

To display

As

Use this code

12

123

00012

00123

00000

12

123

00012

000123

«000»#

123

0123

«0»#

To specify the color for a section in the format code, type the name of one of the following eight colors in the code and enclose the name in square brackets as shown. The color code must be the first item in the code section.

[Black] [Blue] [Cyan] [Green] [Magenta] [Red] [White] [Yellow]

To indicate that a number format will be applied only if the number meets a condition that you have specified, enclose the condition in square brackets. The condition consists of a comparison operator and a value. For example, the following number format will display numbers that are less than or equal to 100 in a red font and numbers that are greater than 100 in a blue font.

[Red][<=100];[Blue][>100]

To hide zeros or to hide all values in cells, create a custom format by using the codes below. The hidden values appear only in the formula bar. The values are not printed when you print your sheet. To display the hidden values again, change the format to the General number format or to an appropriate date or time format.

To hide

Use this code

Zero values

0;–0;;@

All values

;;; (three semicolons)

Use the following keyboard shortcuts to enter the following currency symbols in the Type box.

To enter

Press these keys

¢ (cents)

OPTION + 4

£ (pounds)

OPTION + 3

¥ (yen)

OPTION + Y

€ (euro)

OPTION + SHIFT + 2

The regional settings for currency determine the position of the currency symbol (that is, whether the symbol appears before or after the number and whether a space separates the symbol and the number). The regional settings also determine the decimal symbol and the thousands separator. You can control these settings by using the Mac OS X International system preferences.

To display numbers as a percentage of 100 — for example, to display .08 as 8% or 2.8 as 280% — include the percent sign (%) in the number format.

To display numbers in scientific notation, use one of the exponent codes in the number format code — for example, E–, E+, e–, or e+. If a number format code section contains a zero (0) or number sign (#) to the right of an exponent code, Excel displays the number in scientific notation and inserts an «E» or «e». The number of zeros or number signs to the right of a code determines the number of digits in the exponent. The codes «E–» or «e–» place a minus sign (-) by negative exponents. The codes «E+» or «e+» place a minus sign (-) by negative exponents and a plus sign (+) by positive exponents.

To format dates and times, use the following codes.

Important: If you use the «m» or «mm» code immediately after the «h» or «hh» code (for hours) or immediately before the «ss» code (for seconds), Excel displays minutes instead of the month.

To display

As

Use this code

Years

00-99

yy

Years

1900-9999

yyyy

Months

1-12

m

Months

01-12

mm

Months

Jan-Dec

mmm

Months

January-December

mmmm

Months

J-D

mmmmm

Days

1-31

d

Days

01-31

dd

Days

Sun-Sat

ddd

Days

Sunday-Saturday

dddd

Hours

0-23

h

Hours

00-23

hh

Minutes

0-59

m

Minutes

00-59

mm

Seconds

0-59

s

Seconds

00-59

ss

Time

4 AM

h AM/PM

Time

4:36 PM

h:mm AM/PM

Time

4:36:03 PM

h:mm:ss A/P

Time

4:36:03.75 PM

h:mm:ss.00

Elapsed time (hours and minutes)

1:02

[h]:mm

Elapsed time (minutes and seconds)

62:16

[mm]:ss

Elapsed time (seconds and hundredths)

3735.80

[ss].00

Note: If the format contains AM or PM, the hour is based on the 12-hour clock, where «AM» or «A» indicates times from midnight until noon and «PM» or «P» indicates times from noon until midnight. Otherwise, the hour is based on the 24-hour clock.

See also

Create and apply a custom number format

Display numbers as postal codes, Social Security numbers, or phone numbers

Display dates, times, currency, fractions, or percentages

Highlight patterns and trends with conditional formatting

Display or hide zero values

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Custom Number Formats in Excel

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.

Create a Custom Number Format in Excel

Number Format Codes

A number format string uses up to 4 different codes, separated by semicolons, as shown in the image below.

Custom Number Format Syntax

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.

Example of Custom Number Formats in Chart Axes and Labels

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.

Chart Axis Custom Number Format - Linked to Source

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.

Custom Number Format Color Codes

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.

XLS Color Palette For Custom Number Formats

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;@

Examples of Conditional Operators in Custom Number Formats

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

Содержание

  1. Create and apply a custom number format
  2. Create a custom number format
  3. Apply a custom number format
  4. Delete a custom number format
  5. Create a custom number format
  6. Apply a custom number format
  7. Delete a custom number format
  8. Review guidelines for customizing a number format
  9. Excel custom number formats
  10. Summary
  11. Introduction
  12. What can you do with custom number formats?
  13. Where can you use custom number formats?
  14. What is a number format?
  15. Where can you find number formats?
  16. General is default
  17. How to change number formats
  18. Shortcuts for number formats
  19. Where to enter custom formats
  20. How to create a custom number format
  21. How to edit a custom number format
  22. Structure and Reference
  23. Not all sections required
  24. Characters that display natively
  25. Escaping characters
  26. Placeholders
  27. Automatic rounding
  28. Number formats for TEXT
  29. Number formats for DATES
  30. Number formats for TIME
  31. Number formats for ELAPSED TIME
  32. Number formats for COLORS
  33. Colors by index
  34. Apply number formats in a formula
  35. Measurements
  36. Conditionals
  37. Plural text labels
  38. Telephone numbers
  39. Hide all content

Create and apply a custom number format

If a built-in number format does not meet your needs, you can create a new number format that is based on an existing number format and add it to the list of custom number formats. For example, if you’re creating a spreadsheet that contains customer information, you can create a number format for telephone numbers. You can apply the custom number format to a string of numbers in a cell to format them as a telephone number.

Important: Custom number formats affect only the way a number is displayed and do not affect the underlying value of the number. Custom number formats are stored in the active workbook and are not available to new workbooks that you open.

Create a custom number format

On the Home tab, in the Number group, click More Number Formats at the bottom of the Number Format list .

In the Format Cells dialog box, under Category, click Custom.

In the Type list, select the built-in format that most resembles the one that you want to create. For example, 0.00.

The number format that you select appears in the Type box.

In the Type box, modify the number format codes to create the exact format that you want. For example, 000-000-0000.

Your changes will not alter the built-in format. Instead, your changes create a new custom number format.

When you have finished, click OK.

Apply a custom number format

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

On the Home tab, in the Number group, click More Number Formats at the bottom of the Number Format list .

In the Format Cells dialog box, under Category, click Custom.

At the bottom of the Type list, select the built-in format that you just created. For example, 000-000-0000.

The number format that you select appears in the Type box.

Delete a custom number format

On the Home tab, in the Number group, click More Number Formats at the bottom of the Number Format list .

In the Format Cells dialog box, under Category, click Custom.

In the Type list, select the custom number format, and then click Delete.

Built-in number formats cannot be deleted.

Any cells in the workbook that were formatted with the deleted custom format will be displayed in the default General format.

Create a custom number format

On the Home tab, under Number, on the Number Format pop-up menu , click Custom.

In the Format Cells dialog box, under Category, click Custom.

In the Type list, select the built-in format that most resembles the one that you want to create. For example, 0.00.

The number format that you select appears in the Type box.

In the Type box, modify the number format codes to create the exact format that you want. For example, 000-000-0000.

Your changes will not alter the built-in format. Instead, your changes create a new custom number format.

When you have finished, click OK.

Apply a custom number format

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

On the Home tab, under Number, on the Number Format pop-up menu , click Custom.

In the Format Cells dialog box, under Category, click Custom.

At the bottom of the Type list, select the built-in format that you just created. For example, 000-000-0000.

The number format that you select appears in the Type box.

Delete a custom number format

On the Home tab, under Number, on the Number Format pop-up menu , click Custom.

In the Format Cells dialog box, under Category, click Custom.

In the Type list, select the custom number format, and then click Delete.

Built-in number formats cannot be deleted.

Any cells in the workbook that were formatted with the deleted custom format will be displayed in the default General format.

Источник

Review guidelines for customizing a number format

To create a custom number format, you start by selecting one of the built-in number formats as a starting point. You can then change any one of the code sections of that format to create your own custom number format.

A number format can have up to four sections of code, separated by semicolons. These code sections define the format for positive numbers, negative numbers, zero values, and text, in that order.

For example, you can use these code sections to create the following custom format:

You do not have to include all code sections in your custom number format. If you specify only two code sections for your custom number format, the first section is used for positive numbers and zeros, and the second section is used for negative numbers. If you specify only one code section, it is used for all numbers. If you want to skip a code section and include a code section that follows it, you must include the ending semicolon for the section that you skip.

The following guidelines should be helpful for customizing any of these number format code sections.

Display both text and numbers To display both text and numbers in a cell, enclose the text characters in double quotation marks ( » «) or precede a single character with a backslash ( ). Include the characters in the appropriate section of the format codes. For example, type the format $0.00″ Surplus»;$-0.00″ Shortage» to display a positive amount as «$125.74 Surplus» and a negative amount as «$-125.74 Shortage.» Note that there is one space character before both «Surplus» and «Shortage» in each code section.

The following characters are displayed without the use of quotation marks.

Circumflex accent (caret)

Left curly bracket

Include a section for text entry If included, a text section is always the last section in the number format. Include an «at» character ( @) in the section where you want to display any text that you type in the cell. If the @ character is omitted from the text section, text that you type will not be displayed. If you want to always display specific text characters with the typed text, enclose the additional text in double quotation marks ( » «). For example, «gross receipts for «@

If the format does not include a text section, any non-numeric value that you type in a cell with that format applied is not affected by the format. In addition, the entire cell is converted to text.

Add spaces To create a space that is the width of a character in a number format, include an underscore character ( _), followed by the character that you want to use. For example, when you follow an underscore with a right parenthesis, such as _), positive numbers line up correctly with negative numbers that are enclosed in parentheses.

Repeat characters To repeat the next character in the format to fill the column width, include an asterisk ( *) in the number format. For example, type 0*- to include enough dashes after a number to fill the cell, or type *0 before any format to include leading zeros.

Include double quotation marks To display double quotation marks in the cell, use » (backslash followed by double quotation mark). For example, to display 32 as 32″ in the cell, use #» as the number format.

Include decimal places and significant digits To format fractions or numbers that contain decimal points, include the following digit placeholders, decimal points, and thousand separators in a section.

This digit placeholder displays insignificant zeros if a number has fewer digits than there are zeros in the format. For example, if you type 8.9, and you want it to be displayed as 8.90, use the format #.00.

This digit placeholder follows the same rules as the 0 (zero). However, Excel does not display extra zeros when the number that you type has fewer digits on either side of the decimal than there are # symbols in the format. For example, if the custom format is #.##, and you type 8.9 in the cell, the number 8.9 is displayed.

This digit placeholder follows the same rules as the 0 (zero). However, Excel adds a space for insignificant zeros on either side of the decimal point so that decimal points are aligned in the column. For example, the custom format 0.0? aligns the decimal points for the numbers 8.9 and 88.99 in a column.

This digit placeholder displays the decimal point in a number.

If a number has more digits to the right of the decimal point than there are placeholders in the format, the number rounds to as many decimal places as there are placeholders. If there are more digits to the left of the decimal point than there are placeholders, the extra digits are displayed. If the format contains only number signs (#) to the left of the decimal point, numbers less than 1 begin with a decimal point; for example, .47.

Источник

Excel custom number formats

Summary

Number formats are a key feature in Excel. Their key benefit is that they change how numeric values look without actually changing any data. Excel ships with a huge number of different number formats, and you can easily define your own. This guide explains how custom number formats work in detail.

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.

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

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:

  1. Select cell(s) with values you want to format
  2. Control + 1 > Numbers > Custom
  3. Enter codes and watch preview area to see result
  4. 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:

  1. Positive values
  2. Negative values
  3. Zero values
  4. 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:

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:

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:

The result of the TEXT function is always text, so you are free to concatenate the result of TEXT to other strings:

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:

Notice k appears in quotes («k»). To apply the same format with the TEXT function, you can use simply:

Notice the k is not surrounded by quotes. Alternately, you can add extra double quotes as below, which returns the same result:

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:

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]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:

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 +

Источник

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.

Sample custom number formats

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:

Number format menu on Home tab of Ribbon

This button opens the Format Cells dialog box. You’ll find a complete list of number formats, organized by category, on the Number tab:

Format Cells dialog box on 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.

General number format in narrow column

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.

Custom category in format cells dialog box

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:

  1. Select cell(s) with values you want to format
  2. Control + 1 > Numbers > Custom
  3. Enter codes and watch preview area to see result
  4. 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:

Custom number format structure

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:

  1. Positive values
  2. Negative values
  3. Zero values
  4. 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.

Zero placeholder examples

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.

Pound placeholder examples

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. 

Question mark placeholder examples

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.

Comma placeholder examples

Asterisk (*) is used to repeat characters. The character immediately following an asterisk will be repeated to fill remaining space in a cell.

Asterisk placeholder examples

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.

Underscore placeholder examples

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 format codes for dates

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:

Number format codes for times

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 format codes for elapsed time

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.

Custom number format with colors

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.

Custom number format colors on white

Custom number format colors on gray background

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:

Applying number formats with 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

Number formats for feet and 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

Conditions with custom number formats

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»

Custom number format for plural text

Telephone numbers

Custom number formats can also be used for telephone numbers, as shown in the screen below:

Custom number format for telephone numbers

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

Excel provides many default number formats. But often, these formats are not enough. That’s were custom number formats come into play. Let’s take a look some examples:

Example: The default and a modifyed number format.
  • You want to display number in thousands or millions?
  • Or have a thousands separator for percentage values?
  • Or show a plus sign for positive values?

In such case, you need to create a custom number format. In this article, you learn everything you need to know. For making it easier for you, please feel free to download the example Excel file or the handy custom format card for printing it out.

custom, number, format, excel, insert
Insert a custom number format by pressing Ctrl + 1 on the keyboard and type the code in the text field of the “Custom” category.

Inserting a custom number format in Excel is very easy:

  1. Press Ctrl + 1 on the keyboard and go to “Custom” on the left-hand side.
  2. Now you can enter your own custom number format code.

Recommendation: Select a number format which is very close to your desired format first (number (0) on the screenshot). That way you only have to do some minor changes and don’t have to create the whole format from the scratch.

How do custom formats work?

Structure of custom number formats

If you create a custom number format, you have to regard some rules. A custom number format can be only a few characters or a long text string. They have at least one and at most four parts. Here are the four parts:

  • Each part is divided by the ; (semicolon).
  • A number format must at least have one part. All other parts can be omitted. If omitted, the first part counts for the later numbers. For example: You just define the positive number format. This formatting will be used for negative values, zeros and text (as far as possible).
  • In practice, the fourth part is hardly used.
Structure, custom, number, format, codes, Excel
Structure of custom number format codes in Excel

Let’s go through the 4 sections:

  1. The first part is used for defining positive numbers. Also, if the following parts aren’t used, this format is used for negative number, zeros and text too.
  2. Second part: If you want, you can define a different number format for negative number.
  3. Do you want to have a special format for zeros? You can set it in the third section of the format code.
  4. The fourth part is used for text. If there is no fourth part (and therefore no third semicolon) text will be shown normally. But if you use the fourth part, use the @ sign for showing it. If you don’t insert the add sign, text won’t be displayed.

Important basics for the shortcuts

Sign Description Code Before After
# Add a # for a normal number. The digit won’t be displayed, if there is a preceding zero. #,##0 123
1234
1234.5
0.123
123
1,234
1,235
0
0 (zero) Add a 0 (zero) if there should for sure be a digit displayed, even if it’s a zero. 00000 123 00123
% Add the percentage sign % if you want to display a number as percentage. 0% 0.8 80%
  Don’t use any sign if you want to hide number. Please note: You need at least one semicolon, otherwise Excel will interpret it as “General” ; 123  
, Insert a thousands separator. You can use this for showing numbers in thousands or millions as well (scroll down for more information). #,##0 1234 1,234
. Insert a decimal point in a number. 0.0 123 123.0
[Red] Uses red color.

Please note: Conditional formatting rules offer much more color options.

[Red] 123 123
? If you want to align the decimal points, use the question mark.
Question marks can also be used for fractions.
???.???
0 ???/???
12.345
1234.5
12.34
12.345
1234.5  
12 17/50
“abc” Within quotation marks, you can add any text. “USD “0.0 123.45 USD 123.5
@ The @ sign is only used in the fourth section of the format code. Use it, if you want to display text in a cell. If you don’t use it (but still have 3 semicolons and therefore 4 sections), text will be hidden. @”!” Some text Some text!

Steps for creating your own custom number format

example, custom, number, format, excel
Example: You want to create this number format

There are 3 steps for creating your own custom number format. The idea is to do it as simple as possible and therefore utilize built-in features. The 3 steps are shown with the example on the right-hand side. You want to create a custom number format, which

  • uses thousands separators and 2 decimals,
  • highlights negative number in red font color,
  • displays 0 with no decimals and
  • hides text.

Step 1: Choose a number format in the “Format Cells” window

create, custom, number format, cells, window
First step: Create a number format with the “Format Cells” window.

As the first step, choose a built-in number format which is very close to the one you eventually want to create.

  1. Open the “Format Cells” window by pressing Ctrl + 1 on the keyboard.
  2. Go to “Number“.
  3. Check the tick of the thousands separator and change the decimal numbers to 2.
  4. Click on “OK“.

If you open the “Format Cells” window again and click on “Custom” on the left-hand side, you’ll see the format code. In this example it should be #,##0.00 .

Step 2: Further modify the number format

In this example, you want to further modify the number format for negative values, zeros and text. You continue with the code #,##0.00  created in step 1 above. If there is just one section, the format code is used for all kinds of values: For positive values, negative values, zeros and text because there is no particular definition for negative numbers, zeros and text.

  • For negative values, you want to use the minus sign and use red color.
    • Copy the format code to create a second section. Now you got the format code #,##0.00;#,##0.00 .
    • Add the minus sign to the second part. #,##0.00;-#,##0.00 .
    • Add the code for red color for negative values: #,##0.00;[Red]-#,##0.00 .
  • Zeros should just have one digit.
    • Add a third part to the code above by inserting a semi-colon at the end: #,##0.00;[Red]-#,##0.00;
    • As there should only be one digit, type “0”. #,##0.00;[Red]-#,##0.00;0
  • For a text value, you want to show nothing.
    • Add a forth part to your code and leave it blank. That way, no value will be shown for text.
    • You custom format code now is #,##0.00;[Red]-#,##0.00;0; .

Step 3: Fine-tune the number of decimals

decimal, decimals, digits, number, excel
Fine-tunee the number of decimals

In the last step, you can further fine-tune the number of decimals. Therefore, use the buttons “Increase Decimal” or “Decrease Decimal” in the center of the “Home” ribbon.

Most popular codes

You don’t want to create your own code but just copy & paste one of the most popular custom number formats? Here are the most frequently asked codes.

Thousands + Millions

In many Excel tables, you can see divisions by 1000 or multiplications by 1000 in order to convert values to thousands or millions. An easier and more reliable way is to always use total values and just display them as thousands or millions.

The easiest way: Add a comma “.” to your code.

If you got this code #,##0  just add a comma “,” and you got #,##0, . That way, 2,345 becomes 2.

For more information about thousands and millions, please refer to this article.

Plus sign for positive values

You want to show the plus sign for positive values? For example in charts? Use this code:

  • +0;-0;0  for the following format: +1234 for positive values, -1234 for negative values and 0 for zeroes
  • +#,##0;-#,##0;0  for the following format: +1,234 for positive values, -1,234 and 0 for zeroes.

Do you want to boost your productivity in Excel?

Get the Professor Excel ribbon!

Add more than 120 great features to Excel!


Thousands separator for percentage

Sometimes, you got percentage values larger than 1000%. Excel doesn’t provide a thousands separator for such numbers. The following format adds the thousands separator:

#,##0%

Hide zeros

There are several ways to hide zeroes in Excel. Please refer to this article for more information about the other methods.

If you want to hide zeros with a custom number format, make sure to use a third part of the number format and leave it blank. Some examples:

  • You got this code before: 0 . This is the default number format. In this case you have to add two parts (the second part handles negative values and the third part zeros): 0;-0;
  • You got this code before: #,##0;-#,##0.  Use a third part by just adding a semicolon. #,##0;-#,##0;
  • For percentage numbers: 0%;-0%;

Weekday name, name of the month, number of the year

Do you want to show a weekday name of a given date? You could either do this with formulas or just display the weekday name of a date cell. Use the following codes:

  • Weekday
    • ddd  for the abbreviation: the date 04/21/17 will be shown as “Fri”
    • dddd  for the full name: the date 04/21/17 will be shown as “Friday”
  • Month
    • mmm  for the abbreviation: the date 04/21/17 will be shown as “Apr”
    • mmmm  for the full name: the date 04/21/17 will be shown as “April”
  • Year
    • yy  for just the last two digits: the date 04/21/17 will be shown as “17”
    • yyyy  for the full year number: the date 04/21/17 will be shown as “2017”

Tips and tricks

  • Some formatting can also be done by conditional formatting rules. If your custom number format becomes too complex, please switch to conditional formatting rules. They are usually easier to use and provide more options.
  • Use copy and paste as often as possible. Either for the formatting itself, or for the custom number code. That way, you can save a lot of time.
  • Do you want to change the thousand separator, for example use a full stop instead of a comma? You could achieve this either in the “Region” settings of Windows or override the thousands and decimal separator in Excel. Please refer to this article for more information.

Free Download

download, free, sheet, custom, format, codes
Download this format code sheet for free

As a gift for you, please feel free to download these files:

  • A handy printout with the most common custom format codes. It’s a one-page PDF file. Download it here.
  • The same codes as an Excel table. Maybe it’s easier for you to copy & paste the formats. Download it here.

Was the information in this article helpful? Why don’t you sign up for our free, monthly Excel newsletter?

One more recommendation for custom number formats

favorite, number, format, excel, save
Save your favorite number format and apply it with one click

With our Excel add-in “Professor Excel Tools”, you can create your favorite number format. Even better, you can apply it with just one click. Why don’t you give it a try?


Professor Excel Tools Box

This function is included in our Excel Add-In ‘Professor Excel Tools’

(No sign-up, download starts directly)


Image by Pexels from Pixabay

Понравилась статья? Поделить с друзьями:
  • Excel number format not changing
  • Excel number format codes
  • Excel number as text convert to number one
  • Excel number and text in cell
  • Excel null что это