Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-03-2021 05:03 PM
Hi I am currently trying to round an average, that looks like this:
MATCH (this)-[:HAS_RATING]-(r:Rating)
WITH avg(r.rating) AS ratingAverage
RETURN round(ratingAverage, 2)
This, however, returns:
Too many parameters for function 'round' (line 3, column 20 (offset: 105))
"RETURN round(ratingAverage, 2)"
^
Based on Neo4j docs this should be all I need, any ideas? Thank you in advance!
02-03-2021 05:50 PM
You want to use:
built-in round()
rounds to nearest int.
(google is your friend!)
I also made a PULL REQUEST. I added missing documentation for the Rounding Modes.
02-03-2021 07:28 PM
"google is your friend" is what landed me here: Mathematical functions - numeric - Neo4j Cypher Manual
That not working is what landed me here: How should I be rounding a number to 2 decimal places?
Thanks for sharing the apoc library version.
02-03-2021 09:29 PM
The APOC was in the second spot in Google. Google doesn't always get what you want in the first place!
02-04-2021 01:19 AM
Hello @geronimo4j
Since Neo4j 4.2, your query is valid: Mathematical functions - numeric - Neo4j Cypher Manual
For previous versions, I was not using APOC:
MATCH (this)-[:HAS_RATING]-(r:Rating)
WITH avg(r.rating) AS ratingAverage
RETURN round(ratingAverage * 100) / 100 AS ratingAverage
Regards,
Cobra
02-04-2021 02:18 PM
argh!
Another take home lesson. Make sure you are looking at the latest version of the documentation!
4.2 doc shows all the variants of round that are available for that version:
4.1 doc doesn't show the new variants:
(4.1 doc probably should probably mention that 4.2 has more options.)
Google here, won't point you to the latest doc, unfortunately.
05-31-2021 02:39 PM
Hello,
Sorry raw newbie here!
Does round work with AS in a query?
05-31-2021 02:43 PM
The query above correctly returns my table, but i can't seem to find a way to reduce the remainder precision of the averages!
Any help greatly appreciated.
06-01-2021 06:11 AM
you could use apoc.number.format, for example
return apoc.number.format(1234.34343,'.##')
which returns
1234.34
All the sessions of the conference are now available online