Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
CB CB is offline
external usenet poster
 
Posts: 97
Default Compensating for Excel rounding errors

Hi all,

Im having some issues with the following, which I stumbled across purely by
coincidence. The worksheet was set up by others with more Excel experience
than I so Im not sure as to the best workaround.

FYI, numbers in A1:B3 are entered with only one decimal place. Cells C1:C4
and D4 are calculated. Formulas are noted at the bottom of the post.

The formula in D4 ***appears*** to be incorrect. Since C1:C3 are EXACTLY
-0.5, so is C4. According to the formula, D4 should display O.K. Instead,
it displays Too Low.

I believe the problem lies with the way Excel is storing the numbers (at the
binary level). When troubleshooting, I set cells A1:C3 (and C4) to display
with 30 decimals. I then found the calculation for C3 is not EXACTLY -0.5 as
it should be. Instead, there is a 2 in the fifteenth decimal place.

I tried using the ROUND function in C1:C4 but D4 displays FALSE. D4 still
displays FALSE if I use ROUND in that formula as well.

What am I missing?

Thanks for any and all assistance!

Regards,
Chris



A B C
D
Standard Unit Diff
1 16.3 15.8 -0.5
2 16.2 15.7 -0.5
3 16.1 15.6 -0.5
4 Average Difference -0.5
Too Low

The formula for Diff in C1:C3 is: =IF(A1="","",B1-A1).
The formula for Average Difference in C4 is:
=IF(C1="","",AVERAGE(C1:C3))
The formula for D4 is:
=IF(C4="","",IF(C40.5,"TOO HIGH",IF(C4<-0.5,"TOO LOW",IF(C4-0.5,"O.K."))))



  #2   Report Post  
Posted to microsoft.public.excel.misc
CB CB is offline
external usenet poster
 
Posts: 97
Default Compensating for Excel rounding errors

Hi again,

I **think** I may have found a work-around - sure, just as I'm leaving for
the day! Regardless, I'd appreciate any feedback. The formula for D4 always
struck me as a little more complicated than need be (the final IF statement).
I changed it to the following and all is well.

=IF(C4="","",IF(ROUND(C40.5,1),"TOO HIGH",IF(ROUND(C4<-0.5,1),"TOO
LOW","O.K.")))

I appreciate any and all feedback.

Chris

"CB" wrote:

Hi all,

Im having some issues with the following, which I stumbled across purely by
coincidence. The worksheet was set up by others with more Excel experience
than I so Im not sure as to the best workaround.

FYI, numbers in A1:B3 are entered with only one decimal place. Cells C1:C4
and D4 are calculated. Formulas are noted at the bottom of the post.

The formula in D4 ***appears*** to be incorrect. Since C1:C3 are EXACTLY
-0.5, so is C4. According to the formula, D4 should display O.K. Instead,
it displays Too Low.

I believe the problem lies with the way Excel is storing the numbers (at the
binary level). When troubleshooting, I set cells A1:C3 (and C4) to display
with 30 decimals. I then found the calculation for C3 is not EXACTLY -0.5 as
it should be. Instead, there is a 2 in the fifteenth decimal place.

I tried using the ROUND function in C1:C4 but D4 displays FALSE. D4 still
displays FALSE if I use ROUND in that formula as well.

What am I missing?

Thanks for any and all assistance!

Regards,
Chris



A B C
D
Standard Unit Diff
1 16.3 15.8 -0.5
2 16.2 15.7 -0.5
3 16.1 15.6 -0.5
4 Average Difference -0.5
Too Low

The formula for Diff in C1:C3 is: =IF(A1="","",B1-A1).
The formula for Average Difference in C4 is:
=IF(C1="","",AVERAGE(C1:C3))
The formula for D4 is:
=IF(C4="","",IF(C40.5,"TOO HIGH",IF(C4<-0.5,"TOO LOW",IF(C4-0.5,"O.K."))))



  #3   Report Post  
Posted to microsoft.public.excel.misc
CB CB is offline
external usenet poster
 
Posts: 97
Default Compensating for Excel rounding errors

And...

It also works if I use ROUND in C1:C3 and change D4 accordingly:

=IF(C4="","",IF(C40.5,"TOO HIGH",IF(C4<-0.5,"TOO LOW","O.K.")))

Chris

"CB" wrote:

Hi again,

I **think** I may have found a work-around - sure, just as I'm leaving for
the day! Regardless, I'd appreciate any feedback. The formula for D4 always
struck me as a little more complicated than need be (the final IF statement).
I changed it to the following and all is well.

=IF(C4="","",IF(ROUND(C40.5,1),"TOO HIGH",IF(ROUND(C4<-0.5,1),"TOO
LOW","O.K.")))

I appreciate any and all feedback.

Chris

"CB" wrote:

Hi all,

Im having some issues with the following, which I stumbled across purely by
coincidence. The worksheet was set up by others with more Excel experience
than I so Im not sure as to the best workaround.

FYI, numbers in A1:B3 are entered with only one decimal place. Cells C1:C4
and D4 are calculated. Formulas are noted at the bottom of the post.

The formula in D4 ***appears*** to be incorrect. Since C1:C3 are EXACTLY
-0.5, so is C4. According to the formula, D4 should display O.K. Instead,
it displays Too Low.

I believe the problem lies with the way Excel is storing the numbers (at the
binary level). When troubleshooting, I set cells A1:C3 (and C4) to display
with 30 decimals. I then found the calculation for C3 is not EXACTLY -0.5 as
it should be. Instead, there is a 2 in the fifteenth decimal place.

I tried using the ROUND function in C1:C4 but D4 displays FALSE. D4 still
displays FALSE if I use ROUND in that formula as well.

What am I missing?

Thanks for any and all assistance!

Regards,
Chris



A B C
D
Standard Unit Diff
1 16.3 15.8 -0.5
2 16.2 15.7 -0.5
3 16.1 15.6 -0.5
4 Average Difference -0.5
Too Low

The formula for Diff in C1:C3 is: =IF(A1="","",B1-A1).
The formula for Average Difference in C4 is:
=IF(C1="","",AVERAGE(C1:C3))
The formula for D4 is:
=IF(C4="","",IF(C40.5,"TOO HIGH",IF(C4<-0.5,"TOO LOW",IF(C4-0.5,"O.K."))))



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,346
Default Compensating for Excel rounding errors

Hi,

Round is one solution but here is the problem explained:

Computers work in binary, we work in decimals

Here is everything you need to know about this issue (and more):

http://support.microsoft.com/kb/78113/en-us
http://support.microsoft.com/kb/42980
http://support.microsoft.com/kb/214118
http://www.cpearson.com/excel/rounding.htm
http://docs.sun.com/source/806-3568/ncg_goldberg.html

If this helps, please cliick the Yes button.

Cheers,
Shane Devenshire

"CB" wrote:

And...

It also works if I use ROUND in C1:C3 and change D4 accordingly:

=IF(C4="","",IF(C40.5,"TOO HIGH",IF(C4<-0.5,"TOO LOW","O.K.")))

Chris

"CB" wrote:

Hi again,

I **think** I may have found a work-around - sure, just as I'm leaving for
the day! Regardless, I'd appreciate any feedback. The formula for D4 always
struck me as a little more complicated than need be (the final IF statement).
I changed it to the following and all is well.

=IF(C4="","",IF(ROUND(C40.5,1),"TOO HIGH",IF(ROUND(C4<-0.5,1),"TOO
LOW","O.K.")))

I appreciate any and all feedback.

Chris

"CB" wrote:

Hi all,

Im having some issues with the following, which I stumbled across purely by
coincidence. The worksheet was set up by others with more Excel experience
than I so Im not sure as to the best workaround.

FYI, numbers in A1:B3 are entered with only one decimal place. Cells C1:C4
and D4 are calculated. Formulas are noted at the bottom of the post.

The formula in D4 ***appears*** to be incorrect. Since C1:C3 are EXACTLY
-0.5, so is C4. According to the formula, D4 should display O.K. Instead,
it displays Too Low.

I believe the problem lies with the way Excel is storing the numbers (at the
binary level). When troubleshooting, I set cells A1:C3 (and C4) to display
with 30 decimals. I then found the calculation for C3 is not EXACTLY -0.5 as
it should be. Instead, there is a 2 in the fifteenth decimal place.

I tried using the ROUND function in C1:C4 but D4 displays FALSE. D4 still
displays FALSE if I use ROUND in that formula as well.

What am I missing?

Thanks for any and all assistance!

Regards,
Chris



A B C
D
Standard Unit Diff
1 16.3 15.8 -0.5
2 16.2 15.7 -0.5
3 16.1 15.6 -0.5
4 Average Difference -0.5
Too Low

The formula for Diff in C1:C3 is: =IF(A1="","",B1-A1).
The formula for Average Difference in C4 is:
=IF(C1="","",AVERAGE(C1:C3))
The formula for D4 is:
=IF(C4="","",IF(C40.5,"TOO HIGH",IF(C4<-0.5,"TOO LOW",IF(C4-0.5,"O.K."))))



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,059
Default Compensating for Excel rounding errors

On Nov 24, 2:56*pm, CB wrote:
It also works if I use ROUND in C1:C3 and change D4 accordingly:
=IF(C4="","",IF(C40.5,"TOO HIGH",IF(C4<-0.5,"TOO LOW","O.K.")))


This is closer to the right approach. I would also round the average,
computed in C4. So the formulas should be (presumably C1 is copied
into C2 and C3):

C1: =IF(A1="","",ROUND(B1-A1,1))

C4: =IF(C1="","",ROUND(AVERAGE(C1:C3),1))

Regarding your first posting, you wrote:
numbers in A1:B3 are entered with only one decimal place


But unfortunately, most of the time, WYSI-not-WYG when it comes to
numbers with decimal fractions. Most such numbers are not stored
exactly internally. This leads to small numerical "errors". This is
a limitation of the technology that Excel relies on -- as do most
applications (but not all).

In your example, the problemmatic numbers are in A3:B3. 16.1 and 15.6
are stored internally as exactly
16.10000000000000142108547152020037174224853515625 and
15.59999999999999964472863211994990706443786621093 75. When they are
subtracted, the result is exactly
0.500000000000001776356839400250464677810668945312 5.

As you can see (and you learned empirically), the result is not
exactly 0.5. In fact, Excel will display it as 0.500000000000002 when
formatted as Number with 15 dp.


Regarding your first work-around, you wrote:
=IF(C4="","",IF(ROUND(C40.5,1),"TOO HIGH",
IF(ROUND(C4<-0.5,1),"TOO LOW","O.K.")))


That is nonsensical. For example, you are rounding the boolean result
of C40.5, which is 0 or 1. I suspect you want to write:

=if(C4="", "", if(round(C4,1)0.5, "TOO HIGH", ...etc...)))

Perhaps you did just that in your spreadsheet, and you simply had a
typo when you entered the formula into your posting. Always cut-and-
paste examples to avoid such mistakes in the future.

HTH.


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,059
Default Compensating for Excel rounding errors

PS....

On Nov 24, 4:44*pm, I wrote:
In your example, the problemmatic numbers are in A3:B3. *16.1 and 15.6
are stored internally as exactly
16.10000000000000142108547152020037174224853515625 and
15.59999999999999964472863211994990706443786621093 75.


I did not intend to imply that the numbers in A1:B2 are stored
exactly. In fact, they are not. But coincidentally, their difference
is exactly 0.5, even when we put parentheses around the expression,
which side-steps Excel's attempt to ameliorate such numerical
"errors", and even when we do the computation in VBA.

I want to reiterate that is purely by coincidental. The result of B3-
A3 is much more common.

PS: I also notice that I computed A3-B3, not B3-A3 as you did. That
does not make any difference other than the sign of the result.
  #7   Report Post  
Posted to microsoft.public.excel.misc
CB CB is offline
external usenet poster
 
Posts: 97
Default Compensating for Excel rounding errors

Hi shane,

Thanks for the links. I was familiar with this type of thing once - a life
time ago. :)

Regards,
Chris

"Shane Devenshire" wrote:

Hi,

Round is one solution but here is the problem explained:

Computers work in binary, we work in decimals

Here is everything you need to know about this issue (and more):

http://support.microsoft.com/kb/78113/en-us
http://support.microsoft.com/kb/42980
http://support.microsoft.com/kb/214118
http://www.cpearson.com/excel/rounding.htm
http://docs.sun.com/source/806-3568/ncg_goldberg.html

If this helps, please cliick the Yes button.

Cheers,
Shane Devenshire

"CB" wrote:

And...

It also works if I use ROUND in C1:C3 and change D4 accordingly:

=IF(C4="","",IF(C40.5,"TOO HIGH",IF(C4<-0.5,"TOO LOW","O.K.")))

Chris

"CB" wrote:

Hi again,

I **think** I may have found a work-around - sure, just as I'm leaving for
the day! Regardless, I'd appreciate any feedback. The formula for D4 always
struck me as a little more complicated than need be (the final IF statement).
I changed it to the following and all is well.

=IF(C4="","",IF(ROUND(C40.5,1),"TOO HIGH",IF(ROUND(C4<-0.5,1),"TOO
LOW","O.K.")))

I appreciate any and all feedback.

Chris

"CB" wrote:

Hi all,

Im having some issues with the following, which I stumbled across purely by
coincidence. The worksheet was set up by others with more Excel experience
than I so Im not sure as to the best workaround.

FYI, numbers in A1:B3 are entered with only one decimal place. Cells C1:C4
and D4 are calculated. Formulas are noted at the bottom of the post.

The formula in D4 ***appears*** to be incorrect. Since C1:C3 are EXACTLY
-0.5, so is C4. According to the formula, D4 should display O.K. Instead,
it displays Too Low.

I believe the problem lies with the way Excel is storing the numbers (at the
binary level). When troubleshooting, I set cells A1:C3 (and C4) to display
with 30 decimals. I then found the calculation for C3 is not EXACTLY -0.5 as
it should be. Instead, there is a 2 in the fifteenth decimal place.

I tried using the ROUND function in C1:C4 but D4 displays FALSE. D4 still
displays FALSE if I use ROUND in that formula as well.

What am I missing?

Thanks for any and all assistance!

Regards,
Chris



A B C
D
Standard Unit Diff
1 16.3 15.8 -0.5
2 16.2 15.7 -0.5
3 16.1 15.6 -0.5
4 Average Difference -0.5
Too Low

The formula for Diff in C1:C3 is: =IF(A1="","",B1-A1).
The formula for Average Difference in C4 is:
=IF(C1="","",AVERAGE(C1:C3))
The formula for D4 is:
=IF(C4="","",IF(C40.5,"TOO HIGH",IF(C4<-0.5,"TOO LOW",IF(C4-0.5,"O.K."))))



  #8   Report Post  
Posted to microsoft.public.excel.misc
CB CB is offline
external usenet poster
 
Posts: 97
Default Compensating for Excel rounding errors


"joeu2004" wrote:

On Nov 24, 2:56 pm, CB wrote:
It also works if I use ROUND in C1:C3 and change D4 accordingly:
=IF(C4="","",IF(C40.5,"TOO HIGH",IF(C4<-0.5,"TOO LOW","O.K.")))


This is closer to the right approach. I would also round the average,
computed in C4. So the formulas should be (presumably C1 is copied
into C2 and C3):

C1: =IF(A1="","",ROUND(B1-A1,1))

C4: =IF(C1="","",ROUND(AVERAGE(C1:C3),1))


Good to know I was on the right track.


Regarding your first posting, you wrote:
numbers in A1:B3 are entered with only one decimal place


But unfortunately, most of the time, WYSI-not-WYG when it comes to
numbers with decimal fractions. Most such numbers are not stored
exactly internally. This leads to small numerical "errors". This is
a limitation of the technology that Excel relies on -- as do most
applications (but not all).

In your example, the problemmatic numbers are in A3:B3. 16.1 and 15.6
are stored internally as exactly
16.10000000000000142108547152020037174224853515625 and
15.59999999999999964472863211994990706443786621093 75. When they are
subtracted, the result is exactly
0.500000000000001776356839400250464677810668945312 5.



Interesting!

As you can see (and you learned empirically), the result is not
exactly 0.5. In fact, Excel will display it as 0.500000000000002 when
formatted as Number with 15 dp.


Regarding your first work-around, you wrote:
=IF(C4="","",IF(ROUND(C40.5,1),"TOO HIGH",
IF(ROUND(C4<-0.5,1),"TOO LOW","O.K.")))


That is nonsensical. For example, you are rounding the boolean result
of C40.5, which is 0 or 1. I suspect you want to write:

=if(C4="", "", if(round(C4,1)0.5, "TOO HIGH", ...etc...)))



I thought it seemed rather odd when I was playing around with the formula
but it ***seemed*** to work. I didn't spend a lot of time playing with that
formula when I decided to use round in the other forumlas instead.

Perhaps you did just that in your spreadsheet, and you simply had a
typo when you entered the formula into your posting. Always cut-and-
paste examples to avoid such mistakes in the future.


I believe I did have that in my spreadsheet (briefly) but in looking at it
again I can see why you say it is nonsensical. :)

Thanks for your feedback. I do appreciate it.

Chris

HTH.

  #9   Report Post  
Posted to microsoft.public.excel.misc
CB CB is offline
external usenet poster
 
Posts: 97
Default Compensating for Excel rounding errors



"joeu2004" wrote:

PS....

On Nov 24, 4:44 pm, I wrote:
In your example, the problemmatic numbers are in A3:B3. 16.1 and 15.6
are stored internally as exactly
16.10000000000000142108547152020037174224853515625 and
15.59999999999999964472863211994990706443786621093 75.


I did not intend to imply that the numbers in A1:B2 are stored
exactly. In fact, they are not. But coincidentally, their difference
is exactly 0.5, even when we put parentheses around the expression,
which side-steps Excel's attempt to ameliorate such numerical
"errors", and even when we do the computation in VBA.


I understood your intention. I took programming courses ages and ages ago
and was familiar with how computers stored numbers but that knowledge was
forgotten quite some time ago. This experience has been a refresher. :)


I want to reiterate that is purely by coincidental. The result of B3-
A3 is much more common.

PS: I also notice that I computed A3-B3, not B3-A3 as you did. That
does not make any difference other than the sign of the result.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rounding errors when a "5" is the third decimal place using formul Jbagger Excel Discussion (Misc queries) 4 March 28th 07 01:52 AM
How do I correct rounding errors in Excel formulas? C. Van Dam Excel Worksheet Functions 1 August 29th 06 04:37 AM
Excel Throwing Circular Errors When No Errors Exist MDW Excel Worksheet Functions 1 August 10th 06 02:15 PM
Can rounded numbers be summed without rounding errors? chelseab Excel Discussion (Misc queries) 1 February 8th 06 04:26 AM
Rounding Errors Help mattflow Excel Discussion (Misc queries) 2 August 12th 05 08:10 PM


All times are GMT +1. The time now is 03:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"