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.

Comma value in properties (Europe - 12,43 - Twelve euros and fourth three cents)

tideon
Graph Buddy

Dear Everyone,

I am setting some properties on a few nodes. Here is the query I am attempting to execute.

match (i:Invoice {InvoiceNr:"1456735/2553"})
MERGE (i)-[:SUB_INVOICE]->(si:Invoice{InvoiceNr:"102435433/231",Total:197,30})
RETURN i,si

How do I get the value with the comma to ne escaped. I did a search in the manual for escape characters, but just got stuff on loading CSV data and regular expressions.

Kind regards,
Tideon

13 REPLIES 13

Would converting it to a string first help? What's the aim of having the comma escaped?

Hello,

Becasue I am building the database in europe where we use commas. So 10,20 instead of 10.20

Kind regards,
Tideon

I understand that's the currency separator, but I still don't understand why you want it "escaped"?

I tried to add it to the property and Cypher thinks that everthing after the comma is a new property. So I get an error saying it is expecting a key value pair in essence. So Total: 197 and then OtherPrice: 30

So that is why I thought maybe escaping it would allow cypher to understand what I am trying to do.

You may have a better solution.

Kind regards,
Tideon

Kailash
Graph Buddy

Hi - are you expecting this?
match (i:Invoice {InvoiceNr:"1456735/2553"})
MERGE (i)-[:SUB_INVOICE]->(si:Invoice{InvoiceNr:"102435433/231",Total:"197,30"})
RETURN i,si

or
match (i:Invoice {InvoiceNr:"1456735/2553"})
MERGE (i)-[:SUB_INVOICE]->(si:Invoice{InvoiceNr:"102435433/231",Total:'197,30'})
RETURN i,si

Hello Kailash,

Does the second one allow the 197,30 to remain a number?
As I believe the first one turns it into a string. An I correct?

I need the numbers to do calculations down the line.

Kind regards,
Tideon

No, Sorry . this remains as String

For clarity, both queries will turn it into string?

How do I enter it as a number?

Hi @tideon - I will let others answer but i dont think we can have comma in Int type.

Try this:

return toFloat(replace("197,30", ',', '.'))
result: 197.3

I don't believe that Neo4j has a configurable decimal separator, it recognises only .

Storing your values as strings is probably your best bet, and then if you need to perform calculations on them you can convert using toFloat on the fly e.g:

with "6,10" as firstVal, "5,10" as secondVal
return toFloat(replace(firstVal, ",", ".")) - toFloat(replace(secondVal, ",", "."))

I think you're getting caught up on the visual display of the data vs. how it needs to be stored in a database. Store it as an int 19730, and let the website/UI handle the formatting of the data. Computers don't care about local formatting. Another example of this would be a date. Different regions display dates differently but you still store the information as a date data type and handle the display formatting in the UI.

intouch_vivek
Graph Steward

You have to manage the same on the fly only.

  1. Store 197,30 as string and change to float as mentioned by others
  2. Store as float with "." instead of ","
  3. Store as integer in 2 properties (integral, decimal) and use accordingly
    However in all the case you cannot store float value with "," .
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online