Tuesday, August 15, 2017

Neo4j and Cypher: Rounding Floating Point Numbers/BigDecimals

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:

Fun With SQL: Functions in Postgres

DZone Database Zone Fun With SQL: Functions in Postgres In our previous  Fun with SQL  post on the  Citus Data  blog, we covered w...