Sei sulla pagina 1di 17

11/6/2014

A comprehensive guide to Number Formats in Excel

= MENU =
Jon von der Heyden Excel A comprehensive guide to Number Formats in Excel

Like 20 people like this.

A comprehensive guide to Number Formats in Excel

Contents
Introduction
Structure
Character Codes
- Text Characters
- Number Characters
- Date Characters
- Time Characters
Conditional Number Formats
Using colours
Examples
- Display a signature strip
- Prefix a number with a single character
- Suffix a number with a text string
- Pad a number with n leading zeros
- Right align positive and negative numbers
- Understanding the thousand separator
- Scale a number down by a factor of 1000
- Format percentages
- Display cumulative elapsed time
- Scale a number by a factor of 10
- A quick guide to fractions
- Colour coding cells according to value
- Using symbols within number formats
Further Reading

Introduction
Number formatting in Excel is used to change the way a value appears in a cell or range of cells.
http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

1/17

11/6/2014

A comprehensive guide to Number Formats in Excel

Generally speaking number formatting does not actually alter the value, it only changes the way the we
see the it.
This isnt 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).

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 semicolon (;). These components are, in order;
positive numbers (+ve)
negative numbers (-ve)
zeros
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 neednt 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.
http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

2/17

11/6/2014

A comprehensive guide to Number Formats in Excel

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 zeros. 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.

&

'

<

>

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.

http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

3/17

11/6/2014

A comprehensive guide to Number Formats in Excel

(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 zeros.

(zero) Displays both significant digits (i.e. those entered into the cell),
but also displays insignificant zeros if a number has fewer digits than
there are zeros in the number format code.

Decimal separator. The number of proceeding zeros 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 zeros. 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 Excels 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

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

http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

4/17

11/6/2014

A comprehensive guide to Number Formats in Excel

zeros.
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)

Displays the month as a nqmber 1-12 and does not display


insignificant zeros

mm

Displays the month as a number 01-12 and always displays it as a 2digit 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

Displays the hour as a number 0-23 and does not display insignificant
zeros.

hh

Displays the hour as a number 00-23 and always displays it as a 2digit number.

[h] or [hh]

Displays the cumulative hours elapsed. The time value could for
instance exceed 24 hours (1 day).

Displays the minutes as a number 0-59 and does not display


insignificant zeros. 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 2digit 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.

Displays the seconds as a number 0-59 and does not display


insignificant zeros.

http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

5/17

11/6/2014

A comprehensive guide to Number Formats in Excel

ss

Displays the seconds as a number 00-59 and always displays it as a 2digit 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

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

Whilst the semi-colon (;) is used to delimit the standard four components in a number format, the semicolon 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.
http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

6/17

11/6/2014

A comprehensive guide to Number Formats in Excel

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

COLOUR NAME

HEX VALUE

black

#000000

white

#FFFFFF

red

#FF0000

green

#00FF00

blue

#0000FF

yellow

#FFFF00

magenta

#FF00FF

cyan

#00FFFF

#800000

10

#008000

11

#000080

12

#808000

13

#800080

14

#008080

15

#C0C0C0

http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

7/17

11/6/2014

A comprehensive guide to Number Formats in Excel

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

http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

8/17

11/6/2014

A comprehensive guide to Number Formats in Excel

46

#FF6600

47

#666699

48

#969696

49

#003366

50

#339966

51

#003300

52

#333300

53

#993300

54

#993366

55

#333399

56

#333333

Examples
Display a signature strip:

I cant 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 quarter numbers with Q:

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:
http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

9/17

11/6/2014

A comprehensive guide to Number Formats in Excel

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

Align Positive and Negative numbers:

This is particularly relevant when enclosing numbers in parenthesis to represent negative values. In
doing so the +ve and -ve figures do nit 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 thousand separator formats:

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.
Display figures scaled down by a factor of 1000:
http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

10/17

11/6/2014

A comprehensive guide to Number Formats in Excel

A single comma character is used to scale and round the figure by 1000.

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 negative percentages:

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.
Show cumulative time (hours/minutes/seconds):

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 24Jul-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.
http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

11/17

11/6/2014

A comprehensive guide to Number Formats in Excel

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

- Demonstrating the difference between two times in minutes.

- Demonstrating the difference between two times in seconds.


Display a number scaled (up or down) 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 doesnt
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

http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

12/17

11/6/2014

A comprehensive guide to Number Formats in Excel

Theres 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). Dont 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

Numerator (Integer)

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

# ?/???

2 47/200

2.235

http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

13/17

11/6/2014

A comprehensive guide to Number Formats in Excel

Fraction
Mixed Fraction as
Halves

# ?/2

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 Code cells with RAG status:

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
http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

14/17

11/6/2014

A comprehensive guide to Number Formats in Excel

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
> Microsoft Custom Number Formatting
> Chandoo Factor 10 number scaling
> ASAP Utilities Create a bulleted list
> Daily Dose of Excel Star Rating Format
TAGGED

displaying numbers in a cell, excel, format cells, microsoft excel, ms excel, number format, number

format characters, number format codes, number format syntax, number formats, number formatting.
BOOKMARK THE PERMALINK.

Validate SEDOL

Add, Edit, Delete and Run Access Queries and


Procedures with VBA

4 COMMENTS
http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

15/17

11/6/2014

A comprehensive guide to Number Formats in Excel

Pingback: Excel Tip #16 Disguise Numbers as Text in a Data Validation Drop-down List

Pingback: Excel TEXT Function and Formula Examples

Pingback: dataprose.org PivotTable Flash: Hide Field Captions Custom Number Format Option

Pingback: Excel Custom Number Formats

LEAVE A REPLY
You must be logged in to post a comment.

Like 20 people like this.

RECENT POSTS
Concatenate a Range of Values
Extract a number from a text string with LOOKUP
Translate Text in Excel
Excel Dashboards using PowerPivot, Pivot Tables and Charts
Advanced Excel Management Accountants and Finance Managers
Excel VBA Trainer for Hire
Wotizit?
MrExcel Google Search Engine
How to deal with prank calls
Paragliding Hermanus

TAGS
accdb access database activex data objects ado advanced excel array formula autofill backup bloomberg calculated
columns charts class class module compact access compact and repair criteria dashboards data visualisation excel
excel course formula formulas international securities identification number isin jro macros microsoft excel
Microsoft Jet and Replication Objects ms access ms excel ms query non repeating random number pivot tables rand
randbetween random number sedol stock exchange daily official list training udf unique random number user
defined function vba visual basics for applications worksheet function

ABOUT

http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

16/17

11/6/2014

A comprehensive guide to Number Formats in Excel

Jon von der Heyden

Excel Developer & Trainer


View Full Profile

SEARCH
SEARCH

RSS
Excel Feed (posts only)
Paragliding Feed (posts only)
Eco Feed (posts only)
All Feeds (posts only)

ARCHIVES
September 2013
August 2013
July 2013
June 2013
July 2012
June 2012
May 2012
March 2012

POWERED BY PAABOLA & WORDPRESS.

http://jonvonderheyden.net/excel/a-comprehensive-guide-to-number-formats-in-excel/

17/17

Potrebbero piacerti anche