+ Reply to Thread
Results 1 to 6 of 6

Highlight all cells with one or two decimal places?

  1. #1
    Registered User
    Join Date
    09-10-2015
    Location
    Rochesterm NY
    MS-Off Ver
    2010
    Posts
    1

    Highlight all cells with one or two decimal places?

    I have a list of numbers. They all have decimals. I want to highlight all the cells that have one or two decimal places. Is this possible?

    0.001
    0.9 <--highlight
    0.901
    0.902
    0.903
    0.904
    0.905
    0.906
    0.907
    0.908
    0.909
    0.91 <--highlight
    0.911
    0.912

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,832

    Re: Highlight all cells with one or two decimal places?

    I'm optimistic that most things are possible.

    My first thought begins with the MOD () function. =MOD (number,0.01). This will be 0 for values with two decimal places, and something non-zero for other values.

    The main complication is floating point error (more than you want to know about floating point errors: https://www.excelforum.com/groups/ma...nd-errors.html ). Your "text" list in the OP shows numbers to the nearest thousandth, but we cannot be certain on this side of the internet whether these numbers should be considered exact or not (computers generally cannot represent any decimal number exactly). You need to know enough about your problem to know what precision you expect to test for, then you can use a formula like =MOD (number,0.01) < expected precision. With an appropriate value for expected precision, this formula will return TRUE when the number has one or two decimal places (whenever it is evenly divisible by 0.01) and FALSE when it has more decimal places (is not evenly divisible by 0.01).

    Of course "highlighting" (whatever that means to you) is a matter of conditional formatting or however you want to highlight the values.

    Will something like that work for you.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Highlight all cells with one or two decimal places?

    =rounddown(d2,3)=rounddown(d2,2)

  4. #4
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Highlight all cells with one or two decimal places?

    The following formula results in TRUE for the two cases that the OP wishes to highlight and FALSE otherwise.
    Assuming the data starts in A1:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    I'm not sure if this fully addresses the issues that MrShorty discusses above, but I did test:
    =1.2-1.1
    which, given Excel's limited precision, evaluates to 0.0999999999999999000 and yet the above formula "correctly" (or at least per the OP's wish) returns TRUE. BMV's formula above returns FALSE for this case.
    Geoff

    Did I help significantly? If you wish, click on * Add Reputation to say thanks.
    If your problem has been resolved please select ?Solved? from the Thread Tools menu

  5. #5
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Highlight all cells with one or two decimal places?

    @GeoffW283 LEN(TEXT(11.91, "general"))
    LEN(TEXT(mod(a1;1), "general")) can help but IEEE 754 can brake any solution

    Please Login or Register  to view this content.
    Or for different regional settings
    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,416

    Re: Highlight all cells with one or two decimal places?

    Maybe this...

    =LEN(REPLACE(A1,1,FIND(".",A1),""))<3

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adusting decimal places based on greatest number of places in a series
    By anelson87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2022, 01:05 PM
  2. VBA Function not detecting all 3 decimal places in cells
    By hasanahmad in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-17-2013, 09:22 AM
  3. showing cells to zero Decimal places
    By bumpty in forum Excel General
    Replies: 9
    Last Post: 10-10-2012, 06:47 AM
  4. Decimal places vanish in merged cells
    By thanna in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-10-2012, 05:38 AM
  5. [SOLVED] Editing many cells to ROUND() to 0 decimal places
    By Bozo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-30-2012, 04:37 PM
  6. Decimal places in linked cells
    By abousetta in forum Excel General
    Replies: 5
    Last Post: 02-16-2011, 08:53 AM
  7. Help with formating cells (decimal places)
    By madhead4000 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-03-2006, 04:40 PM
  8. Replies: 4
    Last Post: 02-09-2006, 11:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1