Conditionally Displaying Decimal Places in Excel: Part 1

By David Ringstrom, CPA
 
The simple task of displaying decimal places sometimes causes angst for spreadsheet users. If you have a list of both large and small numbers, there's tension between rounding the small numbers to whole values and making the large numbers harder to read by adding two trailing zeros.
 
In this article, I'll describe how to add decimal places on demand by way of using a custom number format. In Part 2 of this series, I'll demonstrate an alternative that uses the MOD function along with Excel's Conditional Formatting feature.
 
Figure 1 shows a sample report with sales figures. Columns C and D both show currency amounts, so the same formatting can be applied to all cells in those columns. However, in column A, rather than displaying the amount in cell A2 as 3,383.00, we'd like to present it as 3,383, but simultaneously show the amount in cell A3 as 0.50. 
 
Figure 1: You can conditionally display decimals by way of a custom number format.
 
As shown in Figure 1, the simplest approach to our task is to create a custom number format:
 
1. Select the cells to which you wish to apply a conditional number format.
 
2. Press Ctrl-1 to display the Format Cells dialog box. In Excel 2007 and later, you can click the Number button on the Home tab, as shown in Figure 1. Or, in Excel 2003 and Excel for Mac, choose Format and then Cells.
 
3. Choose Custom from the Number tab of the Format Cells dialog box.
 
4. Enter the following formatting code in the Type field: [>=1]#,##0;[<1]0.00
 
5. Click OK to close the Format Cells Dialog box.
 
6. As Figure 1 shows, now numbers less than 1 will be displayed with two decimal places. However, as often is the case in Excel, this simple approach may yield an unintentional side effect. If you change the value of cell A2 to 3383.75, Excel will display 3,384 instead of 3,383.75. (In Part 2 of this series I'll provide a solution for this by way of Excel's Conditional Formatting feature and Excel's MOD function.)
 
Any discussion of custom number formats, such as the one shown in Figure 1, can get deep fast, so I can only offer the briefest of explanations in this article. In this case, I've crafted a conditional number format that tests for two different conditions:
  • [>=1]  This test determines if the number in the cell is greater than or equal to 1. If so, then Excel formats the number to show commas as needed for thousands, millions, and so on, with no trailing decimal places. 
  • [<1]  This test determines if the number in the cell is less than 1, and if so, Excel formats the number with a leading zero and two trailing decimal places.
Within custom number formats, # indicates placeholders to be used when needed, while 0 indicates that either an actual number or a zero placeholder will be shown. Conditional tests such as the ones we've used are placed within square brackets, and each set of conditions is separated by a semicolon. Figure 2 demonstrates how you can apply the custom number format you created to other worksheet cells or remove it from the list when it's no longer needed.
 
Note that custom number formats such as the one shown in Figure 1 apply only to a given workbook, so you'll need to create the formats again if you need this functionality in other spreadsheets as well.
 
Figure 2: You can easily apply custom number formats you create again in the future.
 
Related article:
Read more articles by David Ringstrom. 
 
About the author:

David H. Ringstrom, CPA, heads up Accounting Advisors, Inc., an Atlanta-based software and database consulting firm providing training and consulting services nationwide. Contact David at david@acctadv.com or follow him on Twitter. David speaks at conferences about Microsoft Excel and presents webcasts for several CPE providers, including AccountingWEB partner CPE Link.

 

You may like these other stories...

No field likes its buzzwords more than technology, and one of today's leading terms is "the cloud." But it's not just a matter of knowing what's fashionable. Accounting professionals who know how to use...
There is a growing trend of accountants moving away from traditional compliance work to more advisory work. Client demand is there, but it is up to the accountants to capitalize on that. What should accountants' roles be...
 Event Date: April 24, 2014 In this session Excel expert David Ringstrom, CPA introduces you to a powerful but underutilized macro feature in Excel. David will introduce the Macro Recorder, which transforms actions...

Upcoming CPE Webinars

Apr 22
Is everyone at your organization meeting your client service expectations? Let client service expert, Kristen Rampe, CPA help you establish a reputation of top-tier service in every facet of your firm during this one hour webinar.
Apr 24
In this session Excel expert David Ringstrom, CPA introduces you to a powerful but underutilized macro feature in Excel.
Apr 25
This material focuses on the principles of accounting for non-profit organizations' revenues. It will include discussions of revenue recognition for cash and non-cash contributions as well as other revenues commonly received by non-profit organizations.
Apr 30
During the second session of a four-part series on Individual Leadership, the focus will be on time management- a critical success factor for effective leadership. Each person has 24 hours of time to spend each day; the key is making wise investments and knowing what investments yield the greatest return.