Simple Math Formula But With Unexpected Result

anyremote

New Member
Joined
Oct 15, 2014
Messages
4
Hi,

I tried to compare 2 same result cell but it doesn't match. I put "=(1.81-1.73)/0.01" in cell A1, "=(1.95-1.87)/0.01" in cell B1 & "=IF(A1=B1,"Same","Not Same")" in cell C1.

The result that I got are "8" for cell A1, "8" for cell B1 & "Not Same" for cell C1.

How come it doesn't match? Did I missing something in my formula:confused:

Thanks in advance.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
This is due to the imprecision of floating point arithmetic. Try for example

=IF(ROUND(A1,8)=ROUND(B1,8),"Same","Not Same")
 
Upvote 0
Solution
I tried to compare 2 same result cell but it doesn't match. I put "=(1.81-1.73)/0.01" in cell A1, "=(1.95-1.87)/0.01" in cell B1 & "=IF(A1=B1,"Same","Not Same")" in cell C1. The result that I got are "8" for cell A1, "8" for cell B1 & "Not Same" for cell C1. How come it doesn't match?

If you temporarily format A1 and B1 as Number with 14 decimal places, you will see that they truly are not exactly 8, and they are not equal.

A1: 8.00000000000001
B1: 7.99999999999998

If you want the results to be accurate to 2 decimal places, the formulas should be:

A1: =ROUND((1.81-1.73)/0.01, 2)
B1: =ROUND((1.95-1.87)/0.01, 2)

The reason is: Excel stores numbers in a binary form, and most non-integers cannot be represented exactly in binary.
 
Upvote 0
This is due to the imprecision of floating point arithmetic. Try for example

=IF(ROUND(A1,8)=ROUND(B1,8),"Same","Not Same")

Work perfectly. Thanks.

If you temporarily format A1 and B1 as Number with 14 decimal places, you will see that they truly are not exactly 8, and they are not equal.

A1: 8.00000000000001
B1: 7.99999999999998

If you want the results to be accurate to 2 decimal places, the formulas should be:

A1: =ROUND((1.81-1.73)/0.01, 2)
B1: =ROUND((1.95-1.87)/0.01, 2)

The reason is: Excel stores numbers in a binary form, and most non-integers cannot be represented exactly in binary.

Understood. Thanks for your explanation.
 
Upvote 0

Forum statistics

Threads
1,216,174
Messages
6,129,296
Members
449,498
Latest member
Lee_ray

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top