+ Reply to Thread
Results 1 to 6 of 6

IF/THEN Statement is resulting False, but Should be True

  1. #1
    Registered User
    Join Date
    03-18-2021
    Location
    United States
    MS-Off Ver
    365
    Posts
    3

    IF/THEN Statement is resulting False, but Should be True

    Ok y'all I'm new to using forums, so please forgive me if I do not follow current forum codes of conduct.
    I have an if/then statement that is resulting "awe shucks" in cell F47.
    F47 is dependent on sum(F39:F42) and H40 - H38

    In F49 I subtracted H40 from H38. This should be a two digit decimal, I took it to the 13th decimal place and found a "1". It should be a "0".

    I took H40 to the 15th decimal place and they are all "0"s. Same with H38.

    I know an easy fix is to just use the round function and go to 2 decimal places. But danget Excel shouldn't be this difficult!!
    Attached Files Attached Files
    Last edited by kelli84; 03-19-2021 at 03:01 PM.

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: IF/THEN Statement is resulting False, but Should be True

    Excel is only accurate to 15 digits. Anything after that will show as 0's. I suggest you round to a desirable level, especially as all computers have issues converting back and forth from binary (which is how they do all their math) and decimal (which is how we do our math). So you might expect a sum of 0.5000000000000000 but get 0.4999999999999999
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    03-18-2021
    Location
    United States
    MS-Off Ver
    365
    Posts
    3

    Question Re: IF/THEN Statement is resulting False, but Should be True

    The problem is that when the data is 2 decimal places how does a difference occur in the 13th place?

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,152

    Re: IF/THEN Statement is resulting False, but Should be True

    It is DISPLAYED as 2 decimal places but as post #2 pointed out , internally it may not be so (as per your file)

    An option ...

    =IF(ROUND(SUM(F38:F43),6)=ROUND((H40-H38),6),ROUND(SUM(F38:F43),6),"AWE SHUCKS")

  5. #5
    Registered User
    Join Date
    03-18-2021
    Location
    United States
    MS-Off Ver
    365
    Posts
    3

    Re: IF/THEN Statement is resulting False, but Should be True

    John I entered data to the 2nd decimal place in F2:G23 - which is where the totals that are the source for the formulas.
    That's what is puzzling to me is that these are simple addition formulas.

  6. #6
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: IF/THEN Statement is resulting False, but Should be True

    Quote Originally Posted by kelli84 View Post
    I entered data to the 2nd decimal place in F2:G23 [....] That's what is puzzling to me
    I can understand your puzzlement. If Excel were "only accurate to 15 digits" and your data is accurate to "6 digits", how could there still be a problem?

    The fact is: Excel is __not__ "accurate to 15 digits". As ChemistB and John hinted, the problem is with the internal binary representation of values, namely 64-bit binary floating-point.

    Without getting into the "bits and bytes" details, the simple explanation is: most decimal fractions cannot be represented exactly in 64BFP; and the approximation of a particular decimal fraction might vary depending on the magnitude of a value.

    That is why, for example, IF(10.01 - 10 = 0.01, TRUE) returns FALSE(!).

    In that example, we can see the difference by formatting 10.01-10 to display 17 decimal places (15 significant digits).

    But often, we cannot see the difference because Excel formats only the first 15 significant digits (rounded).

    For example, the following shows the exact decimal representation on the right of the binary approximation of the constants on the left (H40:H43).
    HTML Code: 
    (I use comma to demarcate the first 15 significant digits.)

    As you already know, in general, the best work-around (IMHO) is: whenever we expect a calculation to be accurate to some number of decimal places, explicitly round to that number of decimal places -- and __not__ to an arbitrary number (like 6 or 10). For your example, round to 2 decimal places.

    Someone might suggest setting the "Precision as displayed" option to avoid the need for (most) explicit rounding.

    I do not recommend that option, for many reasons. But if you experiment with it, it is important to make a backup copy of the Excel file before setting the option.

    Merely setting the option can cause irreversible changes to constants that are displayed with less precision.

    And even setting the PAD option might not remedy some problematic calculations. PAD only affects the final value in a cell. It does not affect calculations within a formula.

    So, for example, =H40-H41-H42-H43 might display zero in H47, and =H47=0 might return TRUE. But IF(H40-H41-H42-H43 = 0, TRUE) might still return FALSE(!).
    Last edited by joeu2004; 03-21-2021 at 05:10 PM.

+ 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. This returns a false or a true statement
    By i2trader in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-29-2016, 01:28 PM
  2. True False statement
    By chriswrcg in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-04-2016, 11:41 AM
  3. [SOLVED] True/False if statement
    By Stephen R in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-11-2014, 02:56 PM
  4. How to return a value instead of TRUE/FALSE with IF,OR,AND statement
    By jgoat23 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-14-2014, 10:30 AM
  5. [SOLVED] I need an IF statement that has more than True and False
    By Legend Rubber in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-18-2012, 07:00 AM
  6. If statement with a range and true/false statement
    By aarleblanc in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-20-2012, 06:34 PM
  7. [SOLVED] If resulting in False when it is actually true
    By Papa Jonah in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-18-2005, 12:06 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