+ Reply to Thread
Results 1 to 11 of 11

Conditional Formatting not matching fractional numbers correctly

  1. #1
    Registered User
    Join Date
    03-17-2017
    Location
    Toronto, Canada
    MS-Off Ver
    2007
    Posts
    13

    Red face Conditional Formatting not matching fractional numbers correctly

    Hi there,

    I am trying to make a condition so that if a cell DOES NOT total to .00, .25, .50, .75 that the cell goes a colour (ideally yellow with red font).

    I thought I found a formula to use in conditional formatting, =FLOOR(F9,0.25)<>F9 , but it does not work every time.

    Are there any other suggestions out there? I have attached a copy of the sheet I am working with.

    Thanks for any help anyone can provide!

    Amanda
    Attached Files Attached Files
    Last edited by Aholt; 03-20-2019 at 07:48 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,675

    Re: Conditional Formatting?

    How are you calculating the number in F9? It is usually not reliable on any computer to do exact matches on floating-point numbers like this. It sometimes yields unexpected results. I won't get into a long explanation but if you explain more about what you are doing we might be able to get you a reliable method.

    It might also help to attach your file. The paper clip icon does not work for attachments. To attach a file, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Valued Forum Contributor
    Join Date
    01-07-2013
    Location
    Michigan
    MS-Off Ver
    O365
    Posts
    601

    Re: Conditional Formatting not matching fractional numbers correctly

    Based on your description, this might work as your conditional format formula:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-17-2017
    Location
    Toronto, Canada
    MS-Off Ver
    2007
    Posts
    13

    Re: Conditional Formatting?

    Thank you for the feedback! I will post the sheet now

  5. #5
    Registered User
    Join Date
    03-19-2019
    Location
    London
    MS-Off Ver
    2003-2016/2016 Mac
    Posts
    57

    Re: Conditional Formatting not matching fractional numbers correctly

    Use the following Rules for the third condition, :

    Please Login or Register  to view this content.
    Sample Payroll Sheet 1.xlsx

  6. #6
    Registered User
    Join Date
    03-17-2017
    Location
    Toronto, Canada
    MS-Off Ver
    2007
    Posts
    13

    Re: Conditional Formatting not matching fractional numbers correctly

    Quote Originally Posted by Saqib Qureshi View Post
    Use the following Rules for the third condition, :

    Please Login or Register  to view this content.
    Attachment 616385
    THANK YOU SO MUCH!!

    Do you happen to know why if i put in columns J and K 4:30 PM - 5:30 PM why the total of 1 gets highlighted and red font? I noticed this yesterday before you so generously helped me out!

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,675

    Re: Conditional Formatting not matching fractional numbers correctly

    Quote Originally Posted by Aholt View Post
    Do you happen to know why if i put in columns J and K 4:30 PM - 5:30 PM why the total of 1 gets highlighted and red font? I noticed this yesterday before you so generously helped me out!
    The answer to this goes back to my first post, which I don't think anyone noticed:
    Quote Originally Posted by 6StringJazzer View Post
    How are you calculating the number in F9? It is usually not reliable on any computer to do exact matches on floating-point numbers like this. It sometimes yields unexpected results.
    When you put the time 4:30 and 5:30, you see 1.00 displayed. But the actual value that is calculated is 0.999999999999999*. You can see this if you increase the number of decimals shown in the cell. So it does not actually end in .00 and your conditional formatting rule fails.

    Your formula in column M is

    =L4*24*100/100

    To fix this, change it to

    =ROUND(L4*24*100/100,2)

    Do the same thing in column I.

    __________________________
    *Here is the short version: Excel stores dates and times as days from 1/1/1900. So 4:30 PM is stored as 16.5/24. This comes out exactly as 0.6875. But then you have 5:30, which is stored as 17.5/24, which cannot be expressed exactly as a decimal number. It is 0.72916666... (repeating 6). So when you do arithmetic on them, you don't get an exact answer.

  8. #8
    Registered User
    Join Date
    03-17-2017
    Location
    Toronto, Canada
    MS-Off Ver
    2007
    Posts
    13

    Re: Conditional Formatting not matching fractional numbers correctly

    Quote Originally Posted by 6StringJazzer View Post
    The answer to this goes back to my first post, which I don't think anyone noticed:


    When you put the time 4:30 and 5:30, you see 1.00 displayed. But the actual value that is calculated is 0.999999999999999*. You can see this if you increase the number of decimals shown in the cell. So it does not actually end in .00 and your conditional formatting rule fails.

    Your formula in column M is

    =L4*24*100/100

    To fix this, change it to

    =ROUND(L4*24*100/100,2)

    Do the same thing in column I.

    __________________________
    *Here is the short version: Excel stores dates and times as days from 1/1/1900. So 4:30 PM is stored as 16.5/24. This comes out exactly as 0.6875. But then you have 5:30, which is stored as 17.5/24, which cannot be expressed exactly as a decimal number. It is 0.72916666... (repeating 6). So when you do arithmetic on them, you don't get an exact answer.
    This formula ended up rounding other amounts, which is not what I want to happen. I get what you are saying though.

    It is a little strange because if i put 4:30 AM - 5:30 Am it totals to 1 and doesn't change the cell colour....if i have it 4:30 PM to 5:30 PM it highlights the cell yellow and font red.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,675

    Re: Conditional Formatting not matching fractional numbers correctly

    Quote Originally Posted by Aholt View Post
    This formula ended up rounding other amounts, which is not what I want to happen.
    You are only displaying two decimal places, so why is it a problem to round the value to two decimal places? The underlying value will exactly match what is displayed, which is not true in your original formulas.

    It is a little strange because if i put 4:30 AM - 5:30 Am it totals to 1 and doesn't change the cell colour....if i have it 4:30 PM to 5:30 PM it highlights the cell yellow and font red.
    It is not strange at all if you understand how the calculations are done.

    5:30 AM minus 4:30 AM = 0.0416666666666667

    5:30 PM minus 4:30 PM = 0.0416666666666666

    This is evident if you unhide column L and change the format to General, then increase the number of decimals displayed.

    Therefore, when you multiply back times 24 you get different answers. This is the point I was trying to make about real numbers in a computer.

    I have been in the software development industry for over 35 years and we have two standard solutions to comparing two real numbers:

    1. Round
    2. Test using a tolerance

    In your case rounding is the only solution that makes sense, since you are dealing with time and you don't need high precision.

  10. #10
    Registered User
    Join Date
    03-17-2017
    Location
    Toronto, Canada
    MS-Off Ver
    2007
    Posts
    13

    Re: Conditional Formatting not matching fractional numbers correctly

    Quote Originally Posted by 6StringJazzer View Post
    You are only displaying two decimal places, so why is it a problem to round the value to two decimal places? The underlying value will exactly match what is displayed, which is not true in your original formulas.

    It is not strange at all if you understand how the calculations are done.

    5:30 AM minus 4:30 AM = 0.0416666666666667

    5:30 PM minus 4:30 PM = 0.0416666666666666

    This is evident if you unhide column L and change the format to General, then increase the number of decimals displayed.

    Therefore, when you multiply back times 24 you get different answers. This is the point I was trying to make about real numbers in a computer.

    I have been in the software development industry for over 35 years and we have two standard solutions to comparing two real numbers:

    1. Round
    2. Test using a tolerance

    In your case rounding is the only solution that makes sense, since you are dealing with time and you don't need high precision.
    Sorry that i seem to frustrating you. I am new to using conditional formulas and am just trying to understand. I can't have 4:30 PM 4:35 PM round up to 1 hour, that is what I meant by I can't round up (that is what happened when I tried the formula you suggested).

    I guess I don't understand this enough to use your help.

    Thank you for your time. I guess I will try and explore some other avenues to get this sorted.

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,675

    Re: Conditional Formatting not matching fractional numbers correctly

    I really think I can help you here but I think I need to clarify how to do the rounding. If you have 4:30 PM and 4:35 PM, your result in column I using your existing formula is this:
    noround.JPG

    If you modify your formula to
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    (see post #7)
    then the result in column I is rounded to the nearest hundredth of an hour, not rounded up an hour.
    round2.JPG

    The number you see displayed is the same, but the underlying value now works with your conditional formatting rules.

+ 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. [SOLVED] Conditional Formatting not working correctly
    By patidallas22 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-16-2017, 04:00 PM
  2. Conditional Formatting/Traffic LX style is not formatting correctly
    By christinembater in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-24-2014, 12:32 AM
  3. Conditional Formatting not working correctly
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 5
    Last Post: 12-27-2013, 02:46 PM
  4. Extract Fractional Numbers as Numbers NOT Date
    By MrBill in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-03-2005, 03:50 PM
  5. [SOLVED] Extract Fractional Numbers as Numbers NOT Date
    By MrBill in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-02-2005, 06:17 PM
  6. Replies: 0
    Last Post: 01-04-2005, 08:32 AM
  7. Replies: 0
    Last Post: 01-03-2005, 06:53 PM

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