+ Reply to Thread
Results 1 to 12 of 12

Rounding differences in formula vs. hand-entered

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-11-2011
    Location
    Frederick, MD, USA
    MS-Off Ver
    Excel 2007
    Posts
    125

    Rounding differences in formula vs. hand-entered

    I came across a problem today, where Excel is giving different (displayed) results for what should be identical things.

    In one case, where I use a couple of very simple formula to calculate an average, it displays a result of 0.9. However, if I hand-enter the two numbers, it displays a result of 1.0. (Note that in either case, the exact result in 0.95; just setting decimal display to 1 decimal).

    I've just started using Excel 2013 (through Office 365) after a forced upgrade from 2010, but I'm pretty sure this didn't happen before...

    I've attached a copy of the file in question. A shiny new nickel* to anyone who can tell me why this is happening.


    RoundingDifferences.xlsx




    *Shiny new nickel not included.

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Rounding differences in formula vs. hand-entered

    One is 0.899999999999991 vs. 0.900000000000006
    Attached Images Attached Images

  3. #3
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Rounding differences in formula vs. hand-entered

    I just opened your file in Excel 2010 and it behaves just as you describe for 2013 for 1 and 2 decimal places. The values however are identical to those displayed by JieJenn when taken to many more decimal places.
    Last edited by newdoverman; 11-30-2015 at 03:50 PM.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Rounding differences in formula vs. hand-entered

    I can tell you what is happening and I can speculate why.

    I expanded the numbers to display 20 decimal places. There is a difference in the 15th decimal place. I seem to recall that Excel only carries 15 place precision. In this case the "space holder" before the decimal and 14 places after that are good. I'm assuming that Excel fills in anything after that with random junk. I'm thinking that you "forced" Excel to try to carry this 16th digit because it's the result of a formula (100 - F2).

    This makes me think that multiplication can really screw up precision. It is something I haven' really thought of before.

    Of course, the cure is to use the Round function to knock down the intermediate results to less than 15 significant places.
    Attached Images Attached Images

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Rounding differences in formula vs. hand-entered

    Your computer, and therefore Excel, use a binary floating point format to store numbers. That format cannot store most decimals exactly, in the same sense that a finite base-10 decimal can't be exactly equal to 1/3. When you add or subtract inexact numbers, you frequently get even less exact numbers.

    The manually-entered 99.1 value in F9 is stored as 4058C66666666666 (the hex representation of the 64-bit double-precision number). The SUM formula in F3 returns the result 4058C66666666667; it differs in the least significant bit.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Contributor
    Join Date
    01-11-2011
    Location
    Frederick, MD, USA
    MS-Off Ver
    Excel 2007
    Posts
    125

    Re: Rounding differences in formula vs. hand-entered

    Quote Originally Posted by shg View Post
    Your computer, and therefore Excel, use a binary floating point format to store numbers. That format cannot store most decimals exactly, in the same sense that a finite base-10 decimal can't be exactly equal to 1/3. When you add or subtract inexact numbers, you frequently get even less exact numbers.
    These numbers are pretty far from being inexact; they're all rational numbers. There's no "1/3" being forced to decimal, for example.

    Quote Originally Posted by shg View Post
    The manually-entered 99.1 value in F9 is stored as 4058C66666666666 (the hex representation of the 64-bit double-precision number). The SUM formula in F3 returns the result 4058C66666666667; it differs in the least significant bit.
    If I understand you correctly, you're saying that a result of 0.9 is stored differently if it's the result of a calculation versus a hand-entered number?
    Last edited by Gunther Maplethorpe; 12-01-2015 at 03:12 PM. Reason: My typing skillz are sub-par

  7. #7
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2503
    Posts
    13,702

    Re: Rounding differences in formula vs. hand-entered

    The ubiquitous floating point.

    As dflak suggests I put
    Formula: copy to clipboard
    =ROUND(100-F2,1)
    in J2:J3 and results in K2 and K8 are now identical.
    Dave

  8. #8
    Forum Contributor
    Join Date
    01-11-2011
    Location
    Frederick, MD, USA
    MS-Off Ver
    Excel 2007
    Posts
    125

    Re: Rounding differences in formula vs. hand-entered

    So, why are ANY of the cells going out to the umpteenth decimal? None of the original cells go out that far; none of them have any precision beyond the first decimal.

    More specifically to the point, why do cells J3 and J9 have a difference in their umpteenth decimal place? They should be performing the exact same calculation of (100-99.1)

    (Note: I am aware of ways to fix the problem, but I'd like to understand why it's happening in the first place in order to know when I need to apply such solutions.)

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

    Re: Rounding differences in formula vs. hand-entered

    Quote Originally Posted by Gunther Maplethorpe View Post
    So, why are ANY of the cells going out to the umpteenth decimal? None of the original cells go out that far; none of them have any precision beyond the first decimal.
    Part of the confusion arises because Excel formats only up to 15 significant digits, even though the exact internal representation might be more precise.

    (Note: It does not limit internal representation or arithmetic to 15 significant digits. That is a common misunderstanding that finds its way into most explanations, even Microsoft's explanation in KB 78113 (click here) at http://support.microsoft.com/kb/78113. However, Excel does limit data entry to the first 15 significant digits, replacing digits to the right with zero.)

    So both F3 and F9 appear to be exactly the same, even when formatted to 13 or more decimal places (at least 15 significant digits). But in fact, they are different:
    F3: 99.1000000000000,085265128291212022304534912109375
    F9: 99.0999999999999,94315658113919198513031005859375

    (I use comma to demarcate the first 15 significant digits.)

    The reason for the infinitesimal difference is: the constants in C3:D3 and C9:D9, which are the same, are not exactly as they appear, again due to the Excel formatting limitation. They are:
    1.2: 1.19999999999999,99555910790149937383830547332763671875
    66.9: 66.9000000000000,05684341886080801486968994140625

    The 64-bit binary floating-point representation of these decimal constants is inexact because numbers are approximated by the sum of 53 consecutive powers of 2 ("bits") multiplied by an exponential factor.

    For example, with pencil and paper, try to calculate 0.1 exactly as the sum of 1/16 + 1/32 + 0/64 + .... It cannot be done, even with an "infinite" number of consecutive powers of 2, much less with a limited number.

    Note that F3 is infinitesimally larger than F9. So 100-F3 in J3 is infinitesimally smaller than 100-F9 in J9; and AVERAGE(1,J3) in K2 is infinitesimally smaller than AVERAGE(1,J9) in K8. [1]
    J3: 0.899999999999991,4734871708787977695465087890625
    J9: 0.900000000000005,684341886080801486968994140625
    K2: 0.949999999999995,73674358543939888477325439453125
    K8: 0.950000000000002,8421709430404007434844970703125

    K2 and K8 would appear to be the same if you had formatted to 2 decimal places, which rounds the appearance (not the actual value, in this case). But they appear to be significantly different because you format (round the appearance) to 1 decimal place.

    (If you try to duplicate the arithmetic with pencil and paper and the internal representations above, the results might not be exactly the same. This is because Intel-compatible CPUs actually use an 80-bit binary floating-point representation when performing calculations. But the same principles apply.)


    -----
    [1] Although the following is correct, it is not needed to understand the explanation above. So I moved it into this footnote.

    Sometimes, insignificant (invisible) infinitesimal differences make a signficant (visible) difference, again because of the limited number (53) of consecutive powers of 2. For example, that explains why IF(100.1 - 100 = 0.1, TRUE) returns FALSE(!).

    It takes 6 bits to represent 100; that is, integers in the range of 64 to 127. Ostensibly, that leaves fewer bits (47 = 53 - 6) to represent the decimal fraction; so there are fewer consecutive powers of 2 to sum. That changes the approximation of 1/10 in 100.1.
    Last edited by joeu2004; 12-01-2015 at 03:26 PM. Reason: cosmetic; footnote [1]

  10. #10
    Forum Contributor
    Join Date
    01-11-2011
    Location
    Frederick, MD, USA
    MS-Off Ver
    Excel 2007
    Posts
    125

    Re: Rounding differences in formula vs. hand-entered

    Thanks much for the excellent explanations. Realizing that numbers are stored in non-decimal forms at various steps in the pathway, and that those forms have limitations (separate from decimal notation) was the key to my understanding.

    I also realize now why I see things like ROUND (and its cohorts) in so many other people's formulae where I wouldn't have thought it necessary.

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Rounding differences in formula vs. hand-entered

    Yes, computers cannot store (all) decimals precisely. So the sum of numbers approximating 31.0, 1.2 & 66.9 is not the same as 99.1. Even somewhat trivially, for example in the most basic example - 0.1 + 0.2 = 0.30000000000000004

  12. #12
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,372

    Re: Rounding differences in formula vs. hand-entered

    These numbers are pretty far from being inexact; they're all rational numbers. There's no "1/3" trying to forced to decimal, for example.
    You are correct in saying that they are "rational numbers" (numbers that can be expressed as the ratio of two integers), but not all rational numbers can be represented as terminating decimals in decimal notation, and even fewer rational numbers are terminating decimals in binary notation (where computer's do their computations). For example, the 1/10=0.1 in decimal = 0.000110001100011... in binary. Simply having the 1/10th fraction in the problem introduces rounding error. Only powers of 2 (1/2, 1/4, 1/8, 1/16, etc) will be terminating decimals in binary space, so any fraction beyond those will introduce rounding error.


    If I understand you correctly, you're saying that a result of 0.9 is stored differently if it's the result of a calculation versus a hand-entered number?
    Perhaps not everytime, but in many cases, yes. 0.9 is stored differently depending on the calculation path used to get there.

    In our hypothetical four digit decimal computer, there are several different ways to get 2/3. Hand entered it might be 0.6667. We might calculate 1/3+1/3=0.3333+0.3333=0.6666. Or we might calculate 1-1/3=1-0.3333=0.6667. 3 different approaches and 2 different answers. This is the kind of thing that is going on with just about every computation you perform in Excel (or other computer programming language).
    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: 0
    Last Post: 04-13-2015, 01:01 PM
  2. [SOLVED] Rounding data entered as Millions, how to please
    By Mike in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-04-2006, 06:25 PM
  3. Rounding data entered as Millions, how to please
    By Mike in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-04-2006, 05:40 PM
  4. [SOLVED] Rounding data entered as Millions, how to please
    By Mike in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-04-2006, 05:35 PM
  5. [SOLVED] Hand entered dates view wrong
    By Chris in Nebraska in forum Excel General
    Replies: 6
    Last Post: 08-03-2005, 07:05 PM
  6. [SOLVED] y-axis moves from the left hand side to the right hand side
    By JP in forum Excel General
    Replies: 1
    Last Post: 03-13-2005, 01:06 PM
  7. [SOLVED] y-axis moves from the left hand side to the right hand side!
    By JP in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 03-10-2005, 09: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