Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bill Owens
 
Posts: n/a
Default What is the roundoff error in the subtraction function?

Why does 1.00000000000000000000-0.99950000000000000000=0.000499999999999945
instead of 0.0005? I have 50,000 records that are evenly spaced by 0.0005 and
they appear that way in the column even when viewed with 20 places, however,
after subtracting one number from the other the difference is not 0.0005. I
tried using round off to 4 places and that doesnt resolve the problem. Any
help is appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bernard Liengme
 
Posts: n/a
Default What is the roundoff error in the subtraction function?

This roundoff error results from the way computers (it is not limited to
Excel) store numbers. The IEEE convention requires the decimal number to be
converted to binary with a fixed number of digits. Within this limit some
decimal numbers do no have an exact binary representation.
For more read:
http://support.microsoft.com/default...kb;en-us;78113
http://support.microsoft.com/default...b;en-us;214118
http://www.cpearson.com/excel/rounding.htm
best wishes
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"Bill Owens" <Bill wrote in message
...
Why does
1.00000000000000000000-0.99950000000000000000=0.000499999999999945
instead of 0.0005? I have 50,000 records that are evenly spaced by 0.0005
and
they appear that way in the column even when viewed with 20 places,
however,
after subtracting one number from the other the difference is not 0.0005.
I
tried using round off to 4 places and that doesn't resolve the problem.
Any
help is appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
rsenn
 
Posts: n/a
Default What is the roundoff error in the subtraction function?


Try setting the Precision As Displayed (Tools Options Calculation
Precision As Displayed) and then use a number format with 4 decimal
places.


--
rsenn
------------------------------------------------------------------------
rsenn's Profile: http://www.excelforum.com/member.php...o&userid=29050
View this thread: http://www.excelforum.com/showthread...hreadid=496970

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Jerry W. Lewis
 
Posts: n/a
Default What is the roundoff error in the subtraction function?

You might find my functions at
http://groups.google.com/group/micro...fb95785d1eaff5
to be useful, since they can be used to display more than 15 decimal digits
of the internal representation of numbers. The internal representation of
0.9995 is 0.999500000000000055067..., so the result of your subtraction will
be slightly less than 0.0005 ...

As Bernard has noted, most decimal fractions (including 0.9995 and 0.0005)
cannot be represented exactly in binary, and hence must be approximated.
When you do math with approximate inputs, it should come as no surprise when
the result is only approximate.

A similar thing happens in the VBA currency data type (4 decimal places),
where
CCur(4 / 3) - Cur(2 / 3)
returns 0.3334 instead of 0.6666 instead of 0.6667. The reason why is
probably more intuitively obvious here, but it is basically the same thing.

Absent the use of my functions, you can use Excel's documented 15 digit
limit to think about your math problem as
1.000000000000000 (integers are exactly representable)
-0.999500000000000???
----------------------------
0.000500000000000???
which is consistent with Exel's answer of
0.000499999999999945

I do not understand the OP's complaint about rounding to 4 places and that
not resolving the problem; in Excel
=ROUND(1-0.9995,4)
returns 0.0005 (or more precisely, 0.00050000000000000001 which is as close
as 0.0005 can be approximated in IEEE double precision).

Jerry

"Bernard Liengme" wrote:

This roundoff error results from the way computers (it is not limited to
Excel) store numbers. The IEEE convention requires the decimal number to be
converted to binary with a fixed number of digits. Within this limit some
decimal numbers do no have an exact binary representation.
For more read:
http://support.microsoft.com/default...kb;en-us;78113
http://support.microsoft.com/default...b;en-us;214118
http://www.cpearson.com/excel/rounding.htm
best wishes
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"Bill Owens" <Bill wrote in message
...
Why does
1.00000000000000000000-0.99950000000000000000=0.000499999999999945
instead of 0.0005? I have 50,000 records that are evenly spaced by 0.0005
and
they appear that way in the column even when viewed with 20 places,
however,
after subtracting one number from the other the difference is not 0.0005.
I
tried using round off to 4 places and that doesn't resolve the problem.
Any
help is appreciated.

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
Date & Time mully New Users to Excel 4 May 23rd 05 11:56 AM
Conversion SVC Excel Worksheet Functions 9 February 28th 05 02:29 PM
I cant use englisch function names in a swedich version of excel PE Excel Discussion (Misc queries) 2 December 7th 04 01:00 AM
HOW CAN I GET OFFICE 2003 EXCEL BASIC TO NEST FUNCTIONS LIKE EXCE. Robert AS Excel Worksheet Functions 4 December 2nd 04 10:49 AM
Find a Function to use accross different worksheets R. Hale Excel Worksheet Functions 3 November 25th 04 07:07 AM


All times are GMT +1. The time now is 07:26 PM.

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

About Us

"It's about Microsoft Excel"