Forum Discussion

grafgeorg's avatar
grafgeorg
Copper Contributor
Feb 11, 2023
Solved

Formula gives wrong result

In Excel365 i want to know, if a given cell content is divisable by 10.   For cell R9, which has a value of 11440, i use the formula   =REST(R9;10) . The ouput is 0, as expected.   For cell R10, ...
  • JoeUser2004's avatar
    JoeUser2004
    Feb 11, 2023

    HansVogelaar  wrote:  ``Does it look like [...] 12869,999999999999999``

     

    Well, more likely 12869,999999999900000. (15 significant digits; wink)

     

    Also format the MOD/REST formula to display 15 decimal places.  Does it look something like 9,99999999999999, not actually 10?

     

    The work-around is to round calculated values to the expected precision, based on the precision of the data.  For example:

     

    =REST(ROUND(R10; 0); 10)

     

    Alternatively, round the calculation in R10.

     

    -----

    The reason is:  binary arithmetic anomalies.

     

    The root cause is:  most decimal fractions cannot be represented exactly in 64-bit binary floating-point, which Excel (and most applications) uses to represent numbers internally.  Consequently, numbers with decimal fractions are approximated.

     

    Moreover, the binary approximation of a particular decimal fraction might vary depending on the magnitude of the number, because some binary digits ("bits") must be used to represent the integer part.  That might result in a loss of precision.

     

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

     

Resources