+ Reply to Thread
Results 1 to 11 of 11

Deduction in Excel 2007 gives incorrect value behind decimal

  1. #1
    Registered User
    Join Date
    12-11-2013
    Location
    Riga
    MS-Off Ver
    Excel 2007
    Posts
    6

    Deduction in Excel 2007 gives incorrect value behind decimal

    Hello,

    I have came accross a bug probably because of famous floating dot mathemathics used in Excel. Here is my case:

    1) In two separate cells are values 2992,32 and 2967,15
    2) In another cell I deduct the values one from another and get result 25,17
    3) When I deduct 25,17 from the result I do not get zero. Instead there is 0,00000000000007105427

    Is there any easy way to avoid this issue? I know that I can use round function, but I don't want to do that for every single calculation that I do.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Deduction in Excel 2007 gives incorrect value behind decimal

    The only real alternative to using the ROUND function is to switch on "Set precision as displayed" (Options > Advanced > When calculating this workbook)
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    12-11-2013
    Location
    Riga
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Deduction in Excel 2007 gives incorrect value behind decimal

    Tried that, but it doesn't help.

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Deduction in Excel 2007 gives incorrect value behind decimal

    Looks like you're stuck with using ROUND then!

    The only other option that springs to mind is a bit of code to reduce near zero values to actual zeros - something like this:

    Please Login or Register  to view this content.
    Last edited by Olly; 12-11-2013 at 06:47 AM.

  5. #5
    Registered User
    Join Date
    12-11-2013
    Location
    Riga
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Deduction in Excel 2007 gives incorrect value behind decimal

    Thanks for advice! I prefer to keep it simple without code. Call it lazy, but probably I will go with ROUND in cases when I notice the issue.

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Deduction in Excel 2007 gives incorrect value behind decimal

    Quote Originally Posted by Ronin1981 View Post
    Call it lazy, but probably I will go with ROUND in cases when I notice the issue.
    That's exactly what that code I posted does for you - it monitors changes in your worksheet, and if a value of less than 0.000001 is returned, it changes the formula to round to zero. You simply have to paste that code into the worksheet module, once. That's it.

  7. #7
    Registered User
    Join Date
    12-11-2013
    Location
    Riga
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Deduction in Excel 2007 gives incorrect value behind decimal

    Quote Originally Posted by OllyXLS View Post
    That's exactly what that code I posted does for you - it monitors changes in your worksheet, and if a value of less than 0.000001 is returned, it changes the formula to round to zero. You simply have to paste that code into the worksheet module, once. That's it.
    Ok, I see that it does the trick with formula results, but it doesn't affect values that are not formula. That is good. Now I got my first step in VBA code using. First step is always a bit of pain. Thank you!

  8. #8
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Deduction in Excel 2007 gives incorrect value behind decimal

    Quote Originally Posted by Ronin1981 View Post
    Ok, I see that it does the trick with formula results, but it doesn't affect values that are not formula. That is good.
    Almost - it converts values < 0.000001 to 0, but changes formulas resulting in <0.000001 to a round formula, preserving the original formula, keeping the worksheet dynamic.


    Quote Originally Posted by Ronin1981 View Post
    Now I got my first step in VBA code using. First step is always a bit of pain. Thank you!
    Try it, you'll love it And we're always here to offer help.

  9. #9
    Registered User
    Join Date
    06-10-2014
    Posts
    4

    Re: Deduction in Excel 2007 gives incorrect value behind decimal

    Hello.
    I was looking after a solution for a similar problem.
    It is new for me, although I have been using Excel a lot, for a lot of years.

    My questions:
    "paste the code into the worksheet module" means to create a new module in the VBAProject and pasting it there, like if it was a macro?

    Does this code make the calculation process slower?

    In general, is this floating dot mathematics problem related to newest versions of Excel? or running in 64 bits?

    Thank you.

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

    Re: Deduction in Excel 2007 gives incorrect value behind decimal

    Quote Originally Posted by Sebastián Cabeza View Post
    I was looking after a solution for a similar problem. It is new for me, although I have been using Excel a lot, for a lot of years.
    [....]
    In general, is this floating dot mathematics problem related to newest versions of Excel? or running in 64 bits?
    It is not specific to 64bit versions of Excel. It occurs in 32bit versions as well. And it has been an issue since at least Excel-97, based on Microsoft KBs; but I suspect much longer, perhaps from the very first Excel.

    The problem is due to the inherent nature of 64-bit binary floating-point representation of values and arithmetic. Note: 64-bit binary floating-point is used in 32bit versions of Excel.

    For some idea of the nature of the issue, you might read http://support.microsoft.com/kb/78113.

    But in a nutshell, these problems arise because most most non-integers cannot be represented exactly. That creates infinitesimal differences in most arithmetic. For example, IF(10.1 - 10 = 0.1, TRUE) returns FALSE(!).

    Quote Originally Posted by Sebastián Cabeza View Post
    My questions:
    "paste the code into the worksheet module" means to create a new module in the VBAProject and pasting it there, like if it was a macro?
    No. It means: right-click on the worksheet tab at the bottom of the Excel window, and click on View Code.

    Quote Originally Posted by Sebastián Cabeza View Post
    Does this code make the calculation process slower?
    Technically, yes. But only for the cell(s) just edited. The concomitant recalculation of any dependent cells is not impacted by the Worksheet_Change event macro.

    However, there are other reasons why I would not recommend this approach.

    1. Rounding to 6 decimal places is arbitrary. Instead, you should round to the precision that you expect a calculation to be accurate to. For example, 2 decimal places for many financial calculations.
    2. Arbitrarily rounding all calculations is often not the correct answer. That is one of the many reasons why setting the option "Precision as displayed" is dangerous and not recommended in most circumstances.
    3. The Worksheet_Change event macro (and setting "Precision as displayed") will not correct some rounding problems. For example, IF(10.1 - 10 = 0.1, TRUE) will still return FALSE(!).
    4. I believe olly's Worksheet_Change event macro is flawed, although I have not tested it myself. Try it when the changed cell contains a text value.

    IMHO, it is best to explicitly round each expression that you expect to be accurate to a specifice number of decimal places, even though that might seem tedious.
    Last edited by joeu2004; 06-10-2014 at 12:40 PM. Reason: cosmetic

  11. #11
    Registered User
    Join Date
    06-10-2014
    Posts
    4

    Re: Deduction in Excel 2007 gives incorrect value behind decimal

    IMHO, it is best to explicitly round each expression that you expect to be accurate to a specifice number of decimal places, even though that might seem tedious.
    Ok! It was just my decision!

    My conclusion:
    The differences are very small, mathematically insignificant in most cases.
    The problem is when we pretend to apply certain logical processes, related to balances. I say "balances", meaning to check the result of a calculation process through the use of another calculation process that you logically know might conduce to the same result. Like in your example.
    To avoid the problem in your example, we must calculate [10.1-10], round that result, and then compare it with 0,1.
    It is only a patch, not a solution. So, it seems that we are stuck in that place.
    On the other hand, we could live with that problem, and just do not pretend Excel to compare two results from different calculation methods.
    The good notice is that we just still need our brains!!!

    Thanks for your time, it helped me a lot.

+ 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. CopyFromRecordset incorrect mysql/myODBC 5.1 (excel 2007)
    By ZTHawk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-16-2011, 03:12 AM
  2. Excel 2007 : Decimal places in Excel 2007
    By OtisMardres in forum Excel General
    Replies: 8
    Last Post: 03-13-2011, 09:49 PM
  3. Excel 2007, weeknum() returning incorrect number
    By jakobahman in forum Excel General
    Replies: 3
    Last Post: 08-13-2009, 03:14 AM
  4. Replies: 9
    Last Post: 06-06-2009, 12:09 PM
  5. [SOLVED] adjusting decimal place in protected worksheet in excel 2007
    By Mike in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-17-2006, 09:40 AM

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