How to read currency from a csv file?

Hi,

How can I convert a currency column into a integer from a CSV file directly ?

CSV File
|Price per Item|Price Total|
|€ 258,00|€ 258,00|
|€ 258,00|€ 258,00|
|€ 258,00|€ 258,00|
|€ 258,00|€ 258,00|
|€ 258,00|€ 258,00|
|€ 258,00|€ 258,00|

The property:
"PriceperItem": "� 258,00"

Part of the of the MERGE clause
PriceperItem:coalesce(row.Price per Item,"Unknown"),

Thanks in advance.

This is very specific to your data, but I just removed the currency symbol and replaced the ',' with a decimal point and converted it to an integer. It will truncate the decimal value if it is not zero. You can switch to toFloat() if you have decimal accuracy. Or, you could replace the last three characters with an empty string as another method of conversion.

load csv with headers from "file:///currency.txt" as row FIELDTERMINATOR '|' 
return toInteger(replace(split(row.`Price per Item`,' ')[1], ',','.')) as `Price per Item`,
toInteger(replace(split(row.`Price Total`,' ')[1], ',','.')) as `Price Total`

Great job, Thanks !!!!

1 Like