Share this content

Conditionally Displaying Decimal Places in Excel: Part 2

Nov 23rd 2013
Share this content

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:


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:


Conversely, this formula would return .5 because two doesn't divide evenly into three:


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:


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 [email protected] or follow him on Twitter. David speaks at conferences about Microsoft Excel and presents webcasts for several CPE providers, including AccountingWEB partner CPE Link.

Replies (6)

Comments for this post are now closed.

By Pawel
Jun 25th 2015 20:11 EDT

Does it work in Excel 2003? It seems that we can only format graphic properties in this way.

Thanks (0)
By Doodle
Jun 25th 2015 20:11 EDT

Very unfortunate that it has to be so tricky, but thanks for the explanation! I cannot believe I never thought to use conditional formatting!

Thanks (0)
By imjohnh
Jun 25th 2015 20:12 EDT

I use Excel for Mac 2011 at work, and there appears to be no way to format the numbers to enable a toggle between X decimals places and none. In the attached screen cap, there is no button to format the number based on the two rules.

I'm not sure why the feature would be implemented differently in the Mac version, but it appears to be the case. Bummer.

Thanks (0)
बॉबी ज़ोफन
By zopfan
Sep 4th 2015 07:33 EDT

Thank you man. You saved my day. This was exactly what I was looking for the past 2 days. God bless you man.

2 things, Btw,
Wouldn't it better if you merged both of the lessons into one? Since both together form one idea and one requirement.

2, How did you get this idea? Means how did you that the cell formatting takes precedence over normal conditional formatting or otherwise?

Thanks (0)
By Old Cat Woman
Aug 21st 2017 16:37 EDT

I think I understand the Mod potential but my problem is I already have a formula in the cells that I would like to use from 1 to 3 decimal places. The column I would like to have this affect is based on two other columns. My column uses 0.5,0.125,.0.75 and so forth. How would I add this mod to my existing formula for variable decimal places?

Thanks (0)
By acsteitz
Nov 22nd 2017 11:19 EST

Thanks for the tip! I needed a way to display AT LEAST 2 decimals, i.e. 3.1415 should display as 3.1415 but 3 should display as 3.00. Using your article I came up with
=A1*100=TRUNC(A1*100) as the rule for conditional formatting.

Thanks (0)