MySQL Forums :: General :: Sum of doubles giving incorrect value


Advanced Search

Sum of doubles giving incorrect value
Posted by: Matthew Jenkins ()
Date: January 04, 2011 12:18PM

I have a table (of accounts) with a balance field that is of type 'double'. If the accounts balance, the sum of the balance field of all records should equal 0:

mysql> select balance from accounts;
+---------+
| balance |
+---------+
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| -847 |
| 0 |
| 805.01 |
| 41.99 |
+---------+
12 rows in set (0.01 sec)

So, "SELECT SUM(balance) FROM accounts" should return 0, yes?

mysql> select sum(balance) from accounts;
+---------------------+
| sum(balance) |
+---------------------+
| -7.105427357601e-15 |
+---------------------+
1 row in set (0.00 sec)

I know it's almost 0, but that's gotta be a bug, right?

# /usr/local/libexec/mysqld --version
/usr/local/libexec/mysqld Ver 5.1.49 for portbld-freebsd8.1 on i386 (FreeBSD port: mysql-server-5.1.49)

Options: ReplyQuote


Subject Written By Posted
Sum of doubles giving incorrect value Matthew Jenkins 01/04/2011 12:18PM
Re: Sum of doubles giving incorrect value Matthew Jenkins 01/04/2011 12:31PM
Re: Sum of doubles giving incorrect value Peter Brawley 01/04/2011 01:37PM
Re: Sum of doubles giving incorrect value Matthew Jenkins 01/04/2011 01:42PM
Re: Sum of doubles giving incorrect value Peter Brawley 01/04/2011 01:55PM
Re: Sum of doubles giving incorrect value Rick James 01/04/2011 11:13PM
Re: Sum of doubles giving incorrect value Matthew Jenkins 01/05/2011 03:52AM
Re: Sum of doubles giving incorrect value Rick James 01/05/2011 09:28AM
Re: Sum of doubles giving incorrect value Matthew Jenkins 01/05/2011 10:43AM
Re: Sum of doubles giving incorrect value Rick James 01/06/2011 12:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.