Because there are differences. Double precision floating point is only accurate to 14 digits and there is a difference in the 15th decimal place.
sqlite> SELECT ...> (9.2+7.9+0+4.0+2.6+1.3) - 25.0, ...> (9.2+7.8+0+3.0+1.3+1.7) - 23.0, ...> (9.2+7.9+0+1.0+1.3+1.6) - 21.0; 3.5527136788005e-15|0.0|3.5527136788005e-15 When comparing floating point numbers you should be doing something like this: sqlite> SELECT ...> (9.2+7.9+0+4.0+2.6+1.3), ...> case when abs((9.2+7.9+0+4.0+2.6+1.3) - 25.0) < 1e-14 then "yes" else "no" end, ...> (9.2+7.8+0+3.0+1.3+1.7), ...> case when abs((9.2+7.8+0+3.0+1.3+1.7) - 23.0) < 1e-14 then "yes" else "no" end, ...> (9.2+7.9+0+1.0+1.3+1.6), ...> case when abs((9.2+7.9+0+1.0+1.3+1.6) - 21.0) < 1e-14 then "yes" else "no" end; 25.0|yes|23.0|yes|21.0|yes The number "1e-14" is the "fuzz factor" used to determine the "closeness" of the numbers. See http://en.wikipedia.org/wiki/Floating_point for some information on floating point numbers used by computers. For comparing them see http://floating-point-gui.de/errors/comparison/ and in particular the paper referenced at the end of the page -- which links to a more correct article. > -----Original Message----- > From: sqlite-users-bounces at mailinglists.sqlite.org [mailto:sqlite-users- > bounces at mailinglists.sqlite.org] On Behalf Of Rousselot, Richard A > Sent: Thursday, 22 October, 2015 13:45 > To: 'sqlite-users at mailinglists.sqlite.org' > Subject: [sqlite] Simple Math Question > > Doing the following math, why is it that the results are not all returning > "yes"? > > SELECT > (9.2+7.9+0+4.0+2.6+1.3), > case when (9.2+7.9+0+4.0+2.6+1.3)=25.0 then "yes" else > "no" end, > (9.2+7.8+0+3.0+1.3+1.7), > case when (9.2+7.8+0+3.0+1.3+1.7)=23.0 then "yes" else > "no" end, > (9.2+7.9+0+1.0+1.3+1.6), > case when (9.2+7.9+0+1.0+1.3+1.6)=21.0 then "yes" else > "no" end > FROM > sometable; > > Result > 25.0 no 23.0 yes 21.0 no > > I'm sure this has an obvious answer but it isn't jumping out at me. > > Richard > > This communication is the property of CenturyLink and may contain > confidential or privileged information. Unauthorized use of this > communication is strictly prohibited and may be unlawful. If you have > received this communication in error, please immediately notify the sender > by reply e-mail and destroy all copies of the communication and any > attachments. > _______________________________________________ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users