Conditionally Displaying Decimal Places in Excel: Part 2

By David Ringstrom, CPA
 
In Part 1 of this series I showed how to use a custom number format to conditionally display decimal places. Although the technique is simple, the downside is it may not work in every situation. For instance, the number formats shown in Part 1 would display 0.75 with two decimal places, but would round 4,200.75 up to 4,201 since 4,200.75 is greater than 1. In this article, I'll describe how to use Excel's Conditional Formatting feature to handle just about every imaginable situation.
 
Excel's Conditional Formatting feature is available on the Home tab of Excel 2007 and later for Windows as well as Excel 2011 for Mac, or the Format menu of Excel 2003 and earlier. You can establish up to 64 levels of Conditional Formatting in Excel 2007 and later, or 3 levels in Excel 2003 and earlier.
 
Conditional formatting offers a staggering array of capabilities, but today I'll hone in on a specific technique where we'll use the MOD function to identify when our conditional formatting should be applied. The MOD function takes this form:
=MOD(number,divisor)
 
According to Excel's help documentation, the MOD function "returns the remainder after a number is divided by a divisor." Said differently, MOD returns the amount to the right of the decimal place. For instance, in this case, MOD would return zero because two divides evenly into four:
=MOD(4,2)
 
Conversely, this formula would return .5 because two doesn't divide evenly into three:
=MOD(3,2)
 
Since MOD returns either zero or an amount, we can use it to conditionally display decimal places. We'll simply divide the amount in a cell by 1. If the cell contains a whole number, MOD will return zero, otherwise it will return the decimal portion of the cell's value. It's in this fashion that we'll conditionally format cells with either no decimal places or two decimal places.
 
Figure 1: You can conditionally display decimals by way of the MOD function.
 
To apply conditional formatting, enter numbers into cells A1 through A3, as shown in Figure 1, and then carry out these steps:
 
1. Select the cell or cells you wish to conditionally format.
 
2. Access the Conditional Formatting feature:
  • Excel 2007 and later: Choose Home, Conditional Formatting, New Rule, and then Use a Formula to Determine Which Cells to Format.
  • Excel 2003 and earlier: Choose Format and then Conditional Formatting.
  • Excel 2011 for Mac: From the Home tab, choose Conditional Formatting, and then New Rule, or choose Format and then Conditional Formatting from the menu and then click the Plus sign. When the New Formatting Rule window appears, choose Classic from the Style List, and then specify Use a Formula to Determine Which Cells to Format.
3. Enter the following formula:
=MOD(A1,1)=0
 
4. Click the Format button, click the Number tab, choose 0 decimal places, select Use 1000 Separator (,) and then click OK twice.
 
5. Add the second condition:
  • Excel 2007 and later, Excel 2011 for Mac:  Repeat steps 2 through 4, but this time use the formula =MOD(A1,1)<>0 for step 3 and specify two decimal places in step 4.
  • Excel 2003 and earlier: Choose Format, Conditional Formatting, and then click Add. Specify =MOD(A1,1)<>0 for Condition 2,  and then carry out step 4, but specify two decimal places.
Once applied, you can easily remove conditional formatting:
  • Excel 2007 and later: Select one or more cells, and then choose Home, Conditional Formatting, and make a selection from the Clear Rules menu.
  • Excel 2003 and earlier: Choose Format, Conditional Formatting, Delete, and then remove any unwanted conditions.

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

Event Date: May 29, 2014 In this presentation Excel expert David Ringstrom, CPA brings you up to speed on the Excel feature you should be using, but probably aren't. The Table feature offers the ability to both...
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...

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.