A comprehensive guide to Number Formats in Excel

Introduction

Number formatting in Excel is used to change the way a value appears in a cell or range of cells. Generally speaking number formatting does not actually alter the value, it only changes the way the we see the it.

This isn’t true in all cases, numbers formatted as text are no longer considered as number types and thus it can be suggested that number formatting can change the value of the cell.

A more accurate method of determining a cells true value is to focus on the value as it appears in the formula bar.

When one formats a cell one typically uses the Format Cells dialog (Control+1).

Format Cells Dialog

There are a variety of predefined formats to choose from in the Category list. The underlying code to any one of these formats can be seen by selecting the format from the list and then by immediately proceeding to Custom format. One can define and alter number formats using the Custom category.

Number formatting can be used in some very creative ways. There are many occasions where the unaware user constructs complex formulae to display results, or uses conditional formatting, where an otherwise relatively short number format code would do the same.

Structure

Number formats are separated into four components and each component is separated by a semi-colon (;). These components are, in order;

  1. positive numbers (+ve)
  2. negative numbers (-ve)
  3. zero’s
  4. text values

The semi-colon not only acts as a separator for these specific components, but also acts as a separator for conditional components (but we will get to that later).

One needn’t complete each component of a number format. Where one or more of these components are omitted, Excel will make the following assumptions:

  1. If only one component is used (i.e. there are no semi-colons present in the code), then all numbers will be formatted accordingly, regardless of whether or not the number is +ve, -ve or zero.
  2. If two components are used then the 1st component will be used for both +ve numbers and zero value. The 2nd component is used for -ve numbers.
  3. If three components are used then then 1st component will be used for +ve numbers. The 2nd will be used for -ve numbers. The 3rd will be used for zero’s. Text values will appear as typed.

Thus, any cell formatted with the following code;

;;;

will appear blank regardless of whether or not the cell contains a number (+ve, -ve or 0) or text. Every number format component is complete in this code, yet blank, and hence so shall the appearance of the cell be.

Note: Cell error values (e.g. #N/A) are not affected by number formats.

Character Codes

This section describes what the various characters in a number format code means* These characters can be categorised as Text, Number, Date and Time.

Text Characters

Literal Characters; i.e. these characters will appear in the cell according to where in the number format code they are entered.

$ £ + /
( ) : ! ^
& ~ { }
< > &#61

Special Characters

CHARACTER REMARK
“”

Displays the literal text between the speech marks.
\

Displays the proceeding [single] character as a literal character.
@ Displays the text entered in the cell.
_ (underscore) Displays a single character [blank] space according to the width of the proceeding character (i.e. the proceeding character will not be displayed).
* Displays the proceeding [single] character as many times is required to fill the width of the cell. This proceeding character will always be taken as a literal, regardless of what character is actually used.

Number Characters

CHARACTER REMARK
#

Displays only significant digits (i.e. the numbers entered into the cell). It does not display insignificant zero’s.
0

(zero) Displays both significant digits (i.e. those entered into the cell), but also displays insignificant zero’s if a number has fewer digits than there are zero’s in the number format code.
. Decimal separator. The number of proceeding zero’s will determine how many decimal places are displayed.
, Thousands separator if it proceeds #, or scales a number down by a factor of 1000 if it proceeds 0 (zero).
? Digit placeholder; Displays [blank] spaces for insignificant zero’s. Also used for fractions with varying number of digits.
% Scales a number up by a factor of 100 and suffixes the number with the % symbol.
E+ or E- Displays a number in normalized scientific ‘E’ notation. “E-” places a minus sign by -ve exponents. “E+” places a minus sign by -ve exponents and a plus sign by +ve exponents.
/ Fraction character. See fraction examples later.

Note: The decimal and thousand separator character is determined either by the regional settings, or the chosen characters defined in Excel’s advanced options if one chooses to override the default separators. Be aware therefore that these separators may in fact not be the same as described in this article.

Date Characters

CHARACTER REMARK
d

Displays the day of the month as a number 1-31 (or how many days there are in the given month) and does not display insignificant zero’s.
dd

Displays the day of the month as a number 01-31 (or how many days there are in the given month) and always displays it as a 2-digit number.
ddd Displays the day of the week as Sun-Sat (3 character day)
dddd Displays the day of the week as Sunday-Saturday (complete text)
m Displays the month as a nqmber 1-12 and does not display insignificant zero’s
mm Displays the month as a number 01-12 and always displays it as a 2-digit number.
mmm Disphays the month as Jan-Dec (3 character month).
mmmm Displays the month as January-December (complete text).
mmmmm Displays the month as J-D (only the first character).
yy Displays the last two digits of the year.
yyyy Displays all four digits of the year.

Time Characters

CHARACTER REMARK
h

Displays the hour as a number 0-23 and does not display insignificant zero’s.
hh

Displays the hour as a number 00-23 and always displays it as a 2-digit number.
[h] or [hh] Displays the cumulative hours elapsed. The time value could for instance exceed 24 hours (1 day).
m Displays the minutes as a number 0-59 and does not display insignificant zero’s. Note that this character only represents minutes if used within a complete time number format code.
mm Displays the minutes as a number 00-59 and always displays it as a 2-digit number. Note that this character only represents minutes if used within a complete time number format code.
[m] or [mm] Displays the cumulative minutes elapsed. The time value could for instance exceed 60 minutes.
s Displays the seconds as a number 0-59 and does not display insignificant zero’s.
ss Displays the seconds as a number 00-59 and always displays it as a 2-digit number.
[s] or [ss] Displays the cumulative seconds elapsed. The time value could for instance exceed 60 seconds.
am/pm Displays hours based on the 12-hour clock and indicates morning/afternoon with AM/PM. Note, this is case-sensitive.

Conditional Number Formats

A typical number format already caters for four different conditions. In any single number format code, we can specify a format for +ve numbers, -ve numbers, zero values and text.

However, one can create even more format conditions. Excel provides an ability to format a number according to its’ value.

One does not have to stipulate the exact value for a format; rather one can choose from a whole range of comparison operators.

Comparison Operators

CHARACTER REMARK
=

Equals
<>

Does not equal
< Less than
> More than
<= Less than or equal to
>= More than or equal to

Whilst the semi-colon (;) is used to delimit the standard four components in a number format, the semi-colon is also used to delimit conditions.

Conditions must be enclosed in square brackets, e.g:

[>=1000000]0,, \m;[>=1000]0, \k;0

In the exhibit above, the semi-colon no longer delimits the ordinary components (+ve, -ve, zero, text). The conditional statements now rules the components. In other words, values greater than or equal to 1 million appear scaled to the nearest one million. If the given figure is not greater than or equal to 1 million, but is greater than or equal to 1000, then the figure appears scaled to the nearest one thousand. If neither condition is met then the figure is to be displayed rounded to the nearest whole number.

Using Colours

Another great feature of number formats is to change the font colour of the cell. I use the phrase “change the font colour” loosely, because again cell a values only appear different, the font colour chosen on the ribbon/toolbar will remain unchanged.

Again square brackets [ ] play a role. To format a cell with a colour, one either passes the colour name in square brackets, or one passes the word ‘color’ and the color index in square brackets.

A typical usage is to format -ve figures in red font. For example:

#,##0.0;[red]-#,##0.0

which is the same as:

#,##0.0;[color 3]-#,##0.0

When formatting colour, one has a choice of 8 standard colours by name, or a choice of 56 colours by colour index:

COLOUR INDEX NAME HEX VALUE
1 black #000000
2 white #FFFFFF
3 red #FF0000
4 green #00FF00
5 blue #0000FF
6 yellow #FFFF00
7 magenta #FF00FF
8 cyan #00FFFF
9 #800000
10 #008000
11 #000080
12 #808000
13 #800080
14 #008080
15 #C0C0C0
16 #808080
17 #9999FF
18 #993366
19 #FFFFCC
20 #CCFFFF
21 #660066
22 #FF8080
23 #0066CC
24 #CCCCFF
25 #000080
26 #FF00FF
27 #FFFF00
28 #00FFFF
29 #800080
30 #800000
31 #008080
32 #0000FF
33 #00CCFF
34 #CCFFFF
35 #CCFFCC
36 #FFFF99
37 #99CCFF
38 #FF99CC
39 #CC99FF
40 #FFCC99
41 #3366FF
42 #33CCCC
43 #99CC00
44 #FFCC00
45 #FF9900
46 #FF6600
47 #666699
48 #969696
49 #003366
50 #339966
51 #003300
52 #333300
53 #993300
54 #993366
55 #333399
56 #333333

Examples

h:mm:ss

Display a signature strip

Format Unformatted Formatted Remark
@*_ Signature Signature____________ This text format displays an underscore as many times is needed to extend to the end of the cell, creating a solid line.
I can’t think of many opportunities to use the asterisk character, so this is my feeble attempt at a demonstration. In this exhibit, the solid line for ones signature will always extend the full width of the cell.

Prefix a number with a single character

Format Unformatted Formatted Remark
\Q0 1 Q1 All of these numbers are prefixed with a Q, yet these remain valid numbers.
2 Q2
3 Q3
4 Q4
There may be instances where one has a requirement to prefix or suffix a number with a single character. The benefit of this is that one may yet use the number in subsequent formulae, since this still yields a valid number and not text. This display is achieved by using the \ character to treat the ‘Q’ as a literal value.

Suffix a number with a text string

Format Unformatted Formatted Remark
0 “days”+ 7 7 Days+ All of these numbers are suffixed with ‘Days +’.’Days’ is encapsulated in speech marks to display the literal term. It is not necessary to encapsulate the space and ‘+’ in speech marks as both are literal characters.
14 14 Days+
21 21 Days+
30 30 Days+
This exhibit demonstrates how to include a complete text string using speech marks. The space and plus symbol do not need to be held within the speech marks as they are treated as a literal characters regardless. Again, this still returns a valid number and it can be treated as such in formulae.

Pad a number with n leading zero’s

Format Unformatted Formatted Remark
00000 100 0000100
Any numbers with fewer than 7 digits will be passed with leading zero’s such that the number displayed will always show at least 7 digits.

Align Positive and Negative numbers

Format Unformatted Formatted Remark
0.00_);(0.00) -1234.56 (1234.56) Numbers are displayed rounded to the nearest 2 decimals. Negative numbers are surrounded by parenthesis ().
1234.56 1234.56 As negative numbers are surrounded by parenthesis, positive numbers accommodate a blank space the same width as closing parenthesis such that the numbers align (right-to-left). This is achieved using the underscore character.
This is particularly relevant when enclosing numbers in parenthesis to represent negative values. In doing so the +ve and -ve figures do not align (left-to-right). One uses underscore character to create a blank space and the end of the +ve number with the same width as closing parenthesis.

Understanding the thousand separator

Format Unformatted Formatted Remark
#,##0.0 12345.23 12,345.2 All figures displayed include a thousand separator and appear rounded to one decimal place.
-12345.28 -12,345.3
It is important to note that the last whole number placeholder is a 0 and not #. Take the figure 0.24. Given the current format this would be displayed as “0.2”. However, had the format been #,###.0 (i.e. a # symbol used instead), Excel would only display “.2″. The zero prefix would not be displayed because it is insignificant.
Even if you make the mistake of using a # symbol, Excel will always make this correction regardless.

Scale down a number by a factor of 1,000

Format Unformatted Formatted Remark
0.0,\k 999 1.0 k Figures appear rounded to the nearest multiple of 1000, but with one decimal place. It is good practice to suffix such numbers with ‘k’.
15500 15.5 k
-7200 -7.2 k
A single comma character is used to scale and round the figure by 1000.
Format Unformatted Formatted Remark
0.0,,\m 999000 1.0 m Figures appear rounded to the nearest multiple of 1000000, but with one decimal place. It is good practice to suffix such numbers with ‘m. Note how two scale characters (,) are used to achieve a scale of 1 million.
15500000 15.5 m
-7200000 -7.2 m
Two commas are used to scale and round the figure by 1000000.
Physically dividing a number by 1000 (or 10000) in order to report a scaled down figure is bad practise. This method should be chosen instead. Not only is it unnecessary but it also causes numeric change. Using this number format method does not change the value of the figure, only its’ appearance! The accuracy of figures should not be compromised for the sake of reporting!

Format percentages

Format Unformatted Formatted Remark
0.0 %_);[Red](0.0 %) 0.23 23.0 % Figures appear scaled up by 100. Negative figures appear in the red and encapsulated in parenthesis. A % symbol proceeds figures.
-0.23 (23.0 %)
Some have assumed that because the format cells dialog does not present different formats for negative percentages that it cannot be done. This demonstrates that percentages are merely numbers and thus follow the same rules.

#Display cumulative elapsed time (hours/minutes/seconds)

Format Unformatted Formatted Remark
dd/mm/yy h:mm 41113.60625 23/07/12 14:33
41114.76458 24/07/12 18:21
1.158333333 01/01/00 3:48
[h]:mm 27:48
The typical hour symbol (i.e. h) displays the modulo 24 result. Excel stores time as fractions such that 1 hour is 1/24, 1 minute is 1/24/60 and 1 second is 1/24/60/60. In this exhibit, the difference between 24-Jul-2012 18h21 and 23-Jul-2012 14h33 is 1 day 3 hours and 48 minutes. In Excel this value will be 1.158333333.
Since we are dealing with hours it would be easier to describe the calculation by multiplying 1.58333333 by 24 giving 27.79992 hours. 27.79992 modulo 24 returns 3.79992, which when divided by 24 yields 0.158333333. Note, the integer component (# of days) has effectively been truncated, so there is no cumulative result displayed here, the result is merely 3 hours and 48 minutes.
Enclosing the hour symbol in square brackets (i.e. [h]) instructs Excel to display the cumulative hours of a particular value. Using the current exhibit, we have already established that the difference between the two date and times is 1.158333333. The cumulative difference is thus 1 whole day (24 hours) plus 0.158333333 (3 hours 48 minutes) resulting in 27 hours 48 minutes.
The same principal applies to minutes (m; [m]) and seconds (s; [s]):
Format Unformatted Formatted Remark
h:mm:ss 41113.60625 14:33:01
41114.76458 18:21:42
1.158333333 3:48:41
[m]:ss 228:41
Demonstrating the difference between two times in minutes.
Format Unformatted Formatted Remark
41113.60625 14:33:01
41113.61438 14:44:42
0.0081183 0:11:41
[s].0 701.01
Demonstrating the difference between two times in seconds.

Scale a number by a factor of 10

If the percentage symbol(%) displays a number scaled up by a factor or 100, and the comma symbol (,) displays a number scaled down by a factor of 1000, one can therefore use combinations of these symbols to scale a number by any factor of 10.

The only real downside to the following method is that the percent format always suffixes the number with a percentage symbol. Whilst there is a work-around, it is hardly ideal! The work around in the proceeding examples involves forcing a carriage return before the percentage symbols. This doesn’t remove the percentage symbols but pushes it down to the next line. Thus, if wrap text is turned on for the given cell, and the row height is set only to display 1 line, the percentages appear hidden from view. In these examples, [cr] represents the carriage return. These can be entered in number formats by pressing Control+J.

The following table demonstrates the format method for scaling by a factor of ten. The number of decimal places and such is entirely up to you. I have used 12 decimal places for all numbers only for display purposes. The actual scale display is achieved using the component referred to as the “modifier”.

Using the number 987.654321

BASE 10 COMPONENT NUMBER FORMAT MODIFIER FUNCTION FACTOR RESULT
6 #,##0.000000000000[cr]%%% %%% 100³ 1,000,000 987,654,321.000000000000
5 #,##0.000000000000,[cr]%%%% ,%%%% 100^4 ÷1000 100,000 98,765,432.100000000000
4 #,##0.000000000000[cr]%% %% 100² 10,000 9,876,543.210000000000
3 #,##0.000000000000,[cr]%%% ,%%% 100³ ÷1000 1,000 987,654.321000000000
2 #,##0.000000000000[cr]% % 100 100 98,765.432100000000
1 #,##0.000000000000,[cr]%% ,%% 100² ÷10 10 9,876.543210000000
0 #,##0.000000000000 1 1 987.654321000000
-1 #,##0.000000000000,[cr]% ,% 100 ÷1000 0.1 98.765432100000
-2 #,##0.000000000000,,[cr]%% ,,%% 100² ÷1000² 0.01 9.876543210000
-3 #,##0.000000000000, , 1 ÷1000 0.001 0.987654321000
-4 #,##0.000000000000,,[cr]% ,,% 100 ÷1000² 0.0001 0.098765432100
-5 #,##0.000000000000,,,[cr]%% ,,,%% 100² ÷1000³ 0.00001 0.009876543210
-6 #,##0.000000000000,, ,, 1 ÷100² 0.000001 0.000987654321

There’s a little quirk one should be aware of, so as to not assume that there is something wrong. It seems that after applying some of these formats, when one returns to the format dialog the format code appears different (wrong even). Don’t worry, the format appearance is correct! It appears Excel is confused!

A quick guide to fractions

Format of a fraction: # N/D

# Optional whole number

N Numerator (Integer)

D Denominator (non-zero integer)

Proper Fractions: When the numerator is less than the denominator. E.g.: 3/4

Improper Fractions: When the numerator is greater than the denominator. E.g.: 4/3

Mixed Fractions: When what would otherwise be an improper fraction is represented as the whole part and the remainder expressed as a proper fraction.

Examples representing 2.235 as a fraction:

NUMBER FORMAT CELL DISPLAY PRECISION AS DISPLAYED VALUE
Improper Fraction ?/??? 447/200 2.235
Single-digit Mixed Fraction # ?/? 2 1/4 2.25
Double-digit Mixed Fraction # ?/?? 2 4/17 2.235294
Triple-digit Mixed Fraction # ?/??? 2 47/200 2.235
Mixed Fraction as Halves # ?/2 2 2 2.235
Mixed Fraction as Thirds # ?/3 2 1/3 2.333333
Mixed Fraction as Quarters # ?/4 2 1/4 2.25
Mixed Fraction as Eighths # ?/8 2 2/8 2.25
Mixed Fraction as Tenths # ?/10 2 2/10 2.2

The precision displayed is dependent on the number of denominator digits. Looking at the exhibit above, 2.235 is displayed as 2 1/4 if formatted as single-digit fraction. This equates to 2.25, an imprecision if 0.015. This fraction requires triple-digit format to display full precision.

Fixing the significance of the denominator also affects the precision. The factor is of your own choosing, note however in the exhibit how neither halves, thirds, quarters, eighths or tenths can accurately display 2.235 as a fraction.

Colour coding cells according to value

Unformatted Formatted
150000 150,000
65000 65,000
25000 25,000

Assume the following:

> All values greater than or equal to 100,000 must appear GREEN

> All values greater than or equal to 50,000 must appear AMBER

> All other values must appear RED

Format: [Color4][>=100000]#,##0;[Color46][>=50000]#,##0;#,##0

The order of the conditions in this format is of the utmost importance. Because Excel is configured to be efficient, as soon as any condition is met Excel will no longer evaluate the rest of the format.

Colours applied in number format overrule any font colour applied. Thus, should the cell be formatted as red and none or the conditions met, the font will remain red. As soon as a condition is met however the cell font colour will be inherited from the number format.

Use symbols within number formats

There are two ways of including symbols in your number formats.

  1. Copy the symbol and paste it into the number format code
  2. Use ALT and type the character code using your number keypad

Here are few:

Display 1, 2 or 3 stars in a cell according to whether or not the cell value is 1, 2 or 3: [<2]"«";[<3]"««";"«««";

The chevron character can be typed into a format by holding ALT and typing 0171 on the numpad.

This format requires that the cell be formatted with Webdings font.

Prefix text with a bullet point to create a bullet list: • @

The bullet character can be typed into a format by holding ALT and typing 0149 on the numpad.

Use the degree symbol to display temperature: # °C

The bullet character can be typed into a format by holding ALT and typing 0176 on the numpad.

Further Reading

Comments are closed.