# Sum() of string values

Hi.
I'm new in neo4j and i have a question that i've already tried to solve but nothing.
So, i'm doing a graph and at certain point i have to sum values that i have in a json file, but the value of the field is in string. Here's what i have:

I've readed the neo4j documentation and found the toFloat function, but when i try to do it, i always get null values:

When i try to do: sum(toFloat(C.Preco)) i get this:

What i want to do is to sum all the values from the column: "C.Preco". How do i do it?

Hello,

I think it's not working since in your string there is a "." and a ",".
So you can try to replace the "." and after convert your number to a float.
You can do like this:

`toFloat(replace(C.Preco, ".", ""))`

Looks like you are using European number system
Try below

Or visit below for APOC code
https://neo4j.com/docs/labs/apoc/current/mathematical/number-conversions/

1 Like

Ok nice, it worked. It has converted to float. But how do i sum those values? Just have to put: return sum(tofloat(replace(replace(C.Preco,".",""),",","."))) ?

Ok, it was like i said: return sum(tofloat(replace(replace(C.Preco,".",""),",",".")))
Thank you very much for your kindness!
Stay safe!

Just for u to understand i have this graph:

I want to sum the value of all Contracts that i have(Contrato in the graph), and that attribute is "C.preco" and IF that sum is > 50.000 i want to, somehow, represent on the graph saying that the center Entitity(506858286) is comitting a fraud. Is that possible? I know that neo4j has not if/else clause

Try below

With e1, sum(tofloat(replace(replace(C.Preco,".",""),",","."))) as sumPreco
Where sumPreco >50000
Return e1 as Entity, sumPreco

1. As you are using European number system you can transform 50.000 as per need
2. Neo4j does not have **If Else **, however we have Case Expression
Expressions - Cypher Manual
1 Like

This is what i get.