View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
 
Posts: n/a
Default Problem with TRUNC

Steven_Archer wrote:
the formula is =TRUNC(W152/60)
where in this case W152 is 180.
in some of the cells the result of =TRUNC(180/60) = 3
in the ones which are not working the result is 2.9999999999999
Any ideas? all the formulas and cell settings are identical!


I suspect what you mean to say is: W152 __appears__ to be
180. And I suspect you mean to say: some TRUNC(Wxxx/60)
results are 3, while some other TRUNC(Wxxx/60) results are 2.99...,
where "Wxxx" represents different cells.

I presume that if you wrote literally =TRUNC(180/60), the results
is 3 in every cell. Right?

The point is: what __appears__ to be 180 in a cell is probably
not exactly 180. If you format the Wxxx cells a Number with
14 digits of precision, this might prove the theory.

The "problem" is that real numbers generally cannot be stored
exactly as they appear. This leads to annoying numerical
"errors" of this sort. This is not an Excel problem. It is simply
an anomaly of how (binary) computers represent real numbers
internally.

The "solution" is either to live with the anomaly or to work around
it. The different results for "180" in different cells might actually
be the answer you need. Alternatively, you could set the option
Tools Options Calculation Precision As Displayed.
However, that can have unintended results if you are not careful
with cell formats throughout the spreadsheet. Alternatively, you
could use ROUND() in judicious places instead of relying on cell
formatting to do the rounding for you.