cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Decimal or fixed-point data type in Neo4j? Best-practice alternatives?

jhyot
Node Link

Is there a decimal or fixed-point data type in Neo4j? I'm thinking of something like DECIMAL or NUMBER in various SQL DBs or Java's BigDecimal.

If not, what are the best practices if I need to work with decimal data with Neo4j (saving, calculating, reading)?

My use case is:
I am working with real-world measurements (length, weight etc.) with a given precision. E.g. I have data in meters with a precision of millimeters, i.e. 3 decimal numbers. I'd like to

a) store the numbers with this precision so that I can do equality checks using this precision (i.e. measurement with same millimeter value is equal).
b) read out the numbers with this precision only because any higher apparent precision is meaningless and confusing
c) calculate intermediate (in-memory) values with some higher precision so that intermediate calculations don't introduce additional rounding/cancellation errors

Currency could be another use case, which we don't have, but how do people model that?

1 REPLY 1

Numeric properties created with cypher are either LONG or DOUBLE. When using Java API (e.g. procedures) you can use any java primitive types. That said, Neo4j does not directly allow for BigDecimal et.al. types.

The suggested workaround is using the apoc.number.exact functions from APOC library, see https://neo4j-contrib.github.io/neo4j-apoc-procedures/#exact-math-functions.