Node-Red + MQTT string -> split numbers from letters

Node-Red 4.0.1
Node.js 20.14.0

I get the MQTT Topic as string which includes numbers and letters. I would like to dump the letters to get the number only.

257.01kwh =>> 257.01

or

0.35A =>> 0.35

or

1233.92W =>> 1233.92

How do filter out the letters and change the string to number.

Thanks for your support.

You can use a function node with

msg.payload = parseFloat(msg.payload)
return msg;

And if you want it as a string
use toFixed()

or toString() if rounding is not required.

1 Like

Thanks!! That works well.

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