+ Reply to Thread
Results 1 to 10 of 10

Less Than Equal To Fails at Edge

  1. #1
    Registered User
    Join Date
    01-10-2018
    Location
    London, England
    MS-Off Ver
    Office365
    Posts
    2

    Less Than Equal To Fails at Edge

    Wondering if anyone has a solution for incorrect result of "less than equal to" logic at the edge between true/false. Same spreedsheet works correctly in OpenOffice.

    Problem seems to arise when a number with two digits to right of decimal is used. For example 0.63 is problematic, but if .6 replaces both .63 instances, it is ok.

    Also works correctly in Excel if "A3-B3" is replaced with 0.63 in the formula.

    Thanks

    Excel365.JPG


    Open Office.JPG

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Less Than Equal To Fails at Edge

    IF is not required, try : =ROUND((A3-B3),2)<=B1 and you will get TRUE or FALSE (means the same as Pass, Fail )

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

    Re: Less Than Equal To Fails at Edge

    Computers can be funny about comparing real numbers. Sometimes if you calculate the same number two different ways, a computer will think it's two different numbers. This is a long explanation that I won't give you here, but here is the way around it in this case.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This assumes that you will always have numbers with no more than two digits after the decimal point.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Less Than Equal To Fails at Edge

    You could try rounding.

    =IF(ROUND(A3-B3,2)<=B1, "Pass", "Fail")

    By the way, =IF(A3-B3<=1, "Pass", "Fail") works for me in Excel when the values are entered manually.
    If posting code please use code tags, see here.

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

    Re: Less Than Equal To Fails at Edge

    Actually, it is Open Office that is "wrong" -- albeit perhaps more consistent than Excel with the fudging that both products do.

    In a nutshell, the problem arises because Excel (and Open Office, I assume) represents numeric values using 64-bit binary floating-point.

    The general work-around is to explicitly round calculations with decimal fractions, or whose result might have a decimal fraction, to the degree of accuracy that you expect. In this case, round 12.63-12 to 2 decimal places.

    -----

    In 64-bit binary floating-point, most decimal fractions cannot be represented exactly. Instead, they are approximated by the sum of 53 consecutive powers of 2 ("bits") times an exponential factor.

    Moreover, the approximation of a particular decimal fraction might differ depending on the magnitude of the integer part. The integer part is represented by some of the 53 bits, leaving the sum of fewer bits to approximate the decimal fraction.

    Consequently, binary computer arithmetic often results in infinitesimal differences compared to decimal arithmetic that we do on paper.

    To add to the confusion, Excel formats (displays) only the first 15 significant decimal digits (rounded) that represent the binary value. Consequently, these infinitesimal differences seem to come from nowhere.

    For example, 12.63 is displayed as 12.630000000000000000 when formatted with 18 decimal places; and 0.63 is displayed as 0.630000000000000000. But =12.63-12 is displayed as 0.630000000000001000.

    The exact decimal representation of each binary value is:

    Please Login or Register  to view this content.
    I use period for the decimal point and comma to demarcate the first 15 significant digits.

    -----

    Finally, sometimes =A3-B3<=B1 does not work expected, but =A3-B3-B1 is exactly zero(!), which is 0.00E+00 when formatted as Scientific.

    This is because Excel tries to compensate for the infinitesimal anomalies -- but only sometimes. In the second example, Excel replaces the actual arithmetic result with exactly zero because Excel arbitrarily deterimines that the last subtraction is "close enough" to zero.

    But to demonstrate the inconsistency in this determination, note that =A3-B3-B1<=0 is FALSE(!).

    In Excel (and apparently Open Office), comparison operators round the left and right expressions to 15 significant decimal digits (rounded) before comparing them. 12.63-12 rounds to 0.630000000000001, whereas 0.63 rounds to 0.630000000000000.
    Last edited by joeu2004; 01-10-2018 at 11:32 PM. Reason: minor

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

    Re: Less Than Equal To Fails at Edge

    Quote Originally Posted by Norie View Post
    By the way, =IF(A3-B3<=1, "Pass", "Fail") works for me in Excel when the values are entered manually.
    That's funny, when I do it I reproduce the unexpected result in the OP.

  7. #7
    Registered User
    Join Date
    01-10-2018
    Location
    London, England
    MS-Off Ver
    Office365
    Posts
    2

    Re: Less Than Equal To Fails at Edge

    Thanks for the help everyone! ROUND(A3-B3,2)<=B1 works for my needs.

    I also found that Google Sheets has the same problem.

    Very surprising that this kind of flaw exists at such a large scale. ($0.01)

  8. #8
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Less Than Equal To Fails at Edge

    Google Sheet is not an Excel, Excel is not a Google Sheet

    If that takes care of your original question, & to say Thanks, please click on Add Reputtion (bottom left corner of the post of the person(s) who helped you)
    then select Thread Tools from the menu (top right corner of your thread) and mark this thread as SOLVED.
    If you did it already - ignore it.
    Thank you.

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

    Re: Less Than Equal To Fails at Edge

    Quote Originally Posted by lessthanequalto View Post
    I also found that Google Sheets has the same problem. Very surprising that this kind of flaw exists at such a large scale.
    As I explained, the problem has to do with how numeric values are represented internally. Almost all applications use 64-bit binary floating-point. So it is no surprise that they would have the same problem.

    Open Office might not have the same problem because it rounds to 15 significant digits or because the OO equivalent of Excel's "Precision as displayed" option is set by default or by your choice. Just a guess. OO might play other games.

    BTW, "Precision as displayed" is a very dangerous option. I do not recommend it. Create a backup copy of your Excel file before experimenting with it, if you choose to do so. But Excel PAD will not remedy your specific example. Excel PAD only affects the cell value, not the value of expressions in a formula.

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

    Re: Less Than Equal To Fails at Edge

    I also found that Google Sheets has the same problem.
    Not surprising. This is an inherent bug/feature in all computer (floating point) computations, so I am not surprised that Google Sheets or Open Office or any other spreadsheet app exhibits the same problem. If you expand your research, you will find the same problem in all programming languages, when you choose a floating point data type for your variables. This is an inherent part of floating point calculations, and there is no permanent "fix" to it. If you are interested in further research (and Joeu2004's description in post #5 wasn't enough), I have links to other descriptions of this "problem" here: https://www.excelforum.com/groups/ma...nd-errors.html

    You put a $ on your 0.01 in your latest post, suggesting that maybe these are financial figures you are looking at. One strategy to minimize the effect of floating point error is to use "integers" instead of decimal data. Many/Most programming languages have a "currency" (scaled integer) data type that treats all numbers as integers. Spreadsheets don't have a currency data type, but I suggested one way to simulate a currency data type in this post: https://www.excelforum.com/excel-gen...ml#post4784658

    In a nutshell, if you were not aware of floating point error before, now you are. Now you can work on learning the strategies needed for minimizing the impact of floating point error on your calculations.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ 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. Replies: 1
    Last Post: 03-31-2016, 05:18 PM
  2. how to find the forward edge and aft edge for given coordinates
    By naderassaleh in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 03-08-2014, 02:16 PM
  3. On the edge
    By JonasGrumby in forum Excel General
    Replies: 6
    Last Post: 06-26-2007, 04:44 AM
  4. [SOLVED] Is is possible to set a border NOT on the edge of a cell?
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2006, 10:35 PM
  5. [SOLVED] Setting a cell equal to another worksheet cell fails (sometimes)
    By Richard in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-10-2006, 12:15 AM
  6. Edge Sequence Color
    By smandula in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2005, 06:05 PM
  7. My sanity is teetering on the edge! Help!
    By santiam in forum Excel General
    Replies: 2
    Last Post: 03-01-2005, 12:13 AM

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