String with 2 points from CSV to number

Good morning,

I have a problem with one value from csv, when i get this value i recive a string with 2 points (Ej: 1.480.200) and cant convert into a number.

I need convert this string in a number and divide this value /10000, but i cant divide this as string.

Someone know how to do this?


You can replace the . with "" then do the maths.
here is an example using JSONate

[{"id":"752f9e00aec8eaa2","type":"debug","z":"65617ffeb779f51c","name":"debug 237","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":380,"wires":[]},{"id":"df8cf0d9b3c78ec7","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload ~> |$|{\"col3\": $number( $replace( $.col3,\".\", \"\") ) / 100000}|","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":280,"wires":[["752f9e00aec8eaa2"]]},{"id":"004a11f6ac394aef","type":"csv","z":"65617ffeb779f51c","name":"","sep":",","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":430,"y":200,"wires":[["df8cf0d9b3c78ec7"]]},{"id":"be812d658b23e636","type":"template","z":"65617ffeb779f51c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"one,two,1.234.567\nthree,four,2.345.678\n","output":"str","x":260,"y":200,"wires":[["004a11f6ac394aef"]]},{"id":"3181904b72341cb3","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":200,"wires":[["be812d658b23e636"]]}]


$$.payload ~> |$|{"col3": $number( $replace( $.col3,".", "") ) / 100000}|

Better still, if you didn't store the number in csv with more than 1 period.

1 Like

Thank you so much E1cid, its works so good!

Hi one more time,

Now i find a new problem, the csv that i recive some times the value is 958.245 with only one point and others is 4.248.472 with two points.

When i recive with only one point is read like a number, and with two points like string.

So if i use this code only works when is a string, when is a value because only one point, not works.

Some function to replace both types of data interchangeably?

Thank you in advace.

Set the csv node to not parse numerical values, then all will be strings.

1 Like

Thank you, working fine now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.