+ Reply to Thread
Results 1 to 5 of 5

ROUNDUP not working

  1. #1
    Registered User
    Join Date
    07-28-2017
    Location
    USA
    MS-Off Ver
    365
    Posts
    16

    ROUNDUP not working

    Hello,
    I have a formula that isn't rounding up any number between -.21 thru -.29. The formula works flawlessly for ALL other numbers. I've verified the lookup location cell is formatted like all the others, just won't find the -.3 the roundup function should be giving. If I type in -.3 into C26 I get the values as needed in my cells. the second I drop down to the range I mentioned, I get #N/A. If I use ROUND it works, if I use ROUNDDOWN it works, but gives me the values from the Data! reference table for -.2. Something is broken and won't give me rounded #'s for -.21 to -.29 which needs to ROUNDUP to -.3. Thanks in advance for any help on this issue.

    =IF(J$3="NO",0,IF($C26="","",IF($C26<=49,0,VLOOKUP(IF($D26<0,ROUNDUP($D26,1),ROUNDDOWN($D26,1)),(Data!$A$4:$P$65),3,FALSE))))

    EDIT:
    If I change the lookup option from FALSE to TRUE, I then get values for the -.4 row in the table.

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

    Re: ROUNDUP not working

    The problem is an anomaly with binary arithmetic and the internal implementations of ROUND, ROUNDDOWN and ROUNDUP.

    ROUND(-0.25,1) returns the exact binary representation of -0.3. In other words, MATCH(ROUND(-0.25,1),{-0.3},0) returns 1.

    But ROUNDUP(-0.21,1) does not. In other words, MATCH(ROUNDUP(-0.21,1),{-0.3},0) returns #N/A, indicating no match.

    (But ROUNDUP(-0.21,1)=-0.3 returns TRUE because of a trick that Excel plays. [1])

    Work-around: MATCH(ROUND(ROUNDUP(-0.21,1),1),{-0.3},0)

    I suspect ROUNDDOWN also does not always return the exact binary representation, although it seems to work for some values that result in 0.2 and 0.3.

    I think it would be prudent to use ROUND(ROUNDDOWN($D26,1),1) as well.

    (I'm in a hurry. I might post more details later.)

    PS.... Changing from VLOOKUP(...,FALSE) to VLOOKUP(...,TRUE) might seem to work because VLOOKUP does not look for an exact match. However, whether or not it always matches the correct row is coincidental, since the internal binary result of ROUNDUP (and ROUNDDOWN) might be infinitesimally less than expected in some cases.


    -----
    [1] Not a trick, so much as a limitation. For comparison operators ("=", "<>", etc) and similar operations (SUMIF, COUNTIF, etc), Excel compares the left and right operands rounded to 15 significant decimal digits. But for lookup comparisons (MATCH, VLOOKUP, etc), Excel compares the internal binary representations.
    Last edited by joeu2004; 09-12-2018 at 04:22 PM. Reason: PS; footnote [1]

  3. #3
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: ROUNDUP not working

    can you attach a small file with your data?
    I just tried =Roundup(xx,1) function with values in the -.21 thru -.29 range and it works fine.
    1. Click on the * Add Reputation if you think this helped you
    2. Mark your thread as SOLVED when question is resolved

    Modytrane

  4. #4
    Registered User
    Join Date
    07-28-2017
    Location
    USA
    MS-Off Ver
    365
    Posts
    16

    Re: ROUNDUP not working

    Quote Originally Posted by joeu2004 View Post
    The problem is an anomaly with binary arithmetic and the internal implementations of ROUND, ROUNDDOWN and ROUNDUP.

    ROUND(-0.25,1) returns the exact binary representation of -0.3. In other words, MATCH(ROUND(-0.25,1),{-0.3},0) returns 1.

    But ROUNDUP(-0.21,1) does not. In other words, MATCH(ROUNDUP(-0.21,1),{-0.3},0) returns #N/A, indicating no match.

    (But ROUNDUP(-0.21,1)=-0.3 returns TRUE because of a trick that Excel plays.)

    Work-around: MATCH(ROUND(ROUNDUP(-0.21,1),1),{-0.3},0)

    I suspect ROUNDDOWN also does not always return the exact binary representation, although it seems to work for some values that result on 0.2 and 0.3.

    I think it would be prudent to use ROUND(ROUNDDOWN($D26,1),1) as well.

    (I'm in a hurry. I might post more details later.)

    PS.... Changing from VLOOKUP(...,FALSE) to VLOOKUP(...,TRUE) might seem to work because VLOOKUP does not look for an exact match. However, whether or not it always matches the correct row is coincidental, since the internal binary result of ROUNDUP (and ROUNDDOWN) might be infinitesimally less than expected in some cases.
    This works! Thanks and I'd like more information when you have more time on it. Much appreciated!

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

    Re: ROUNDUP not working

    First, I believe the following simplification does what you want without encountering any anomalies:

    VLOOKUP(INT($D26*10)/10, Data!$A$4:$P$65, 3, FALSE)

    If you want to exercise an abundance of caution, you could write ROUND(INT($D26*10)/10,1). But I believe the explicit rounding is superfluous in this particular case.

    -----

    To explain further....

    Excel uses the industry-standard 64-bit binary floating-point to represent numeric values internally. Consequently, most decimal fractions cannot be represented exactly. And the binary representation of the same decimal fraction varies depending on the magnitude of the integer part of the value.

    That gives rise to such anomalies as IF(10.01 - 10 = 0.01, TRUE) returns FALSE(!). These anomalies are not considered to be defects. Instead, they are accepted consequences of choosing that form of representation internally. (FYI, choosing any other form of representation is no panacea, in general.)

    To further complicate things, Excel applies some heuristics of its own in order to mask some anomalies in very specific cases. However, the heuristics are applied inconsistently. Consequently, we can have cases where A1=A2 is TRUE, but A1-A2=0 is FALSE, and cases where A1=A2 is FALSE, but (only the formula) =A1-A2 returns exact zero (0.00E+00 when formatted as Scientific). Those anomalies are unique to Excel.

    In general, the work-around is: whenever we expect a calculation to be accurate to "n" decimal places, explicitly round to that number of decimal places using ROUND. (Do not round to an arbitrary number of decimal places, as some people suggest.)

    For your example (it does not matter whether we use positive or negative numbers)....

    Please Login or Register  to view this content.
    I use period for the decimal point and comma to demarcate the first 15 significant digits, which is all that Excel will format (rounded).

    Note the difference between ROUNDUP(0.23,1) and 0.3 and between ROUNDUP(2.23,1) and 2.3. In contrast, note that no such difference arises between ROUNDUP(1.23,1) and 1.3. So whether or not a difference arises is difficult to predict.

    Based on many years of experiments, I am very confident that ROUND "always" returns the correct binary representation. ("Always" except for a known defect.)

    I do not have the same degree of experience with ROUNDDOWN. But based on some random testing, it seems to always return the correct binary representation, as well.
    Last edited by joeu2004; 09-12-2018 at 11:25 PM. Reason: Minor improvements

+ 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] Sum, Roundup, then Sum again
    By shargreaves in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-01-2018, 01:47 PM
  2. [SOLVED] Roundup
    By mahershams in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-25-2014, 08:09 AM
  3. ROUNDUP help please
    By wilksy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-08-2013, 06:09 AM
  4. RoundUp
    By rbpd5015 in forum Excel General
    Replies: 6
    Last Post: 04-12-2010, 11:51 AM
  5. Roundup
    By rdaled in forum Excel General
    Replies: 1
    Last Post: 01-05-2007, 03:52 PM
  6. roundup
    By david.madden in forum Excel General
    Replies: 6
    Last Post: 10-27-2006, 08:24 AM
  7. ROUNDUP copy/paste and fill handle not working
    By Jason Southco in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-10-2005, 01:05 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