0

I'm studying Neo4J and liking it a lot so far, but encountered a strange issue involving sum of floating point values. I have several transactions which I need to sum, after some filtering, all of them have up to 2 decimal values (for example: -39.68, -2.48, 3.40, and so on. If I copy these values to an excel spreadsheet, the sum of all of them, yields 9575.00, but in Neo4J the result is 9574.999999999998.

I have the same values stored in a SQLServer database, and there I also get 9575.00.

Of course I could just round the result, using Mark Needhams solution http://www.markhneedham.com/blog/2014/05/25/neo4j-cypher-rounding-a-float-value-to-decimal-places/, but this just seems strange, especially because it's not an operation that should change the number decimals.

Anybody facing the same issue?

Daniel
  • 2,744
  • 1
  • 31
  • 41
  • Quite possibly all them are producing the same sum, but Excel and SQL are showing you rounded results because their default output rounds to a limited number of digits (thus concealing the true value). If Neo4J is using binary floating-point, then it is impossible for values in it to be exactly -39.68, -2.48, or 3.40, because all values must be rational numbers with a denominator that is a power of two. See [this question](https://stackoverflow.com/questions/588004/is-floating-point-math-broken). – Eric Postpischil Dec 11 '17 at 23:32
  • You're quite right, Eric! Thanks for your answer! Just followed your link and read (https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html#680) this guide.... very interesting. – Wolf Goebel Dec 22 '17 at 20:49

0 Answers0