Rounding Numbers.

G

GEM

How can I round a number to two decimals. Not using the increase/decrease
decimals. For example...

I get an answer like this, 2.41666666666667, I know that if you lower the
decimals to two units, the cell will show the answer 2.42, but if I use this
cell in a calculation it will still use 2.41666666666667, and will give me an
incorrect answer.

100 * 2.41666666666667 = 241.6666667
100 * 2.42 = 242
 
J

joeu2004

In B1: =100*ROUND(A1,2)

Although that is sufficient for the OP's example, it is not always the
case. So in general, I would do ROUND(100*ROUND(A1,2),0) if the
intention is get exactly the same internal representation as we would
get if we entered the integral constant.

Consider the case where A1 is the constant 2.00666666666667.
100*ROUND(A1,2) in B1 seems to result in 201; in fact, (B1 = 201)
results in TRUE. But (B1-200 = 1) results in FALSE.

Of course, the reason is that although ROUND(A1,2) has the same
internal representation as the constant 2.01, 2.01 cannot be
represented exactly in IEEE floating-point [*]. So when we multiply
by 100, we do not get exactly 201. Then when we subtract 200, the
difference between the result and 1 is large enough that Excel does
not consider them equal.

[*] In contrast, in the OP's example, although 2.42 also cannot be
represented exactly internally, 100*ROUND(A1,2) does result in exactly
the same internal representation as the constant 242.


----- original posting -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top