DZone Database Zone
Neo4j and Cypher: Rounding Floating Point Numbers/BigDecimals
I was doing some data cleaning a few days ago and wanting to multiply a value by one million. My Cypher code to do so looked like this:
with "8.37" as rawNumeric RETURN toFloat(rawNumeric) * 1000000 AS numeric ╒═════════════════╕ │"numeric" │ ╞═════════════════╡ │8369999.999999999│ └─────────────────┘Unfortunately, that suffers from the classic rounding error when working with floating point numbers. I couldn’t figure out a way to solve it using pure Cypher, but there tends to be an APOC function to solve every problem... and this was no exception.
No comments:
Post a Comment