Create decimal value

HI

I am receiving av value from a temp sensor in the range from 0 to 400.
I need to create a desimal value like this, 0 to 0.0 and 400 to 40.0

How can i do this?

Hi and welcome to the forum.

There are a few ways to do that.

But for the sake of helping you with one way, it could be done with a function node.

The message you receive it handled by the function node and then returns a value within your range.

That is easy as basically you are dividing the number by 10.

So it would look like this:

var x = msg.payload/10;
x = parseInt(x);
msg.payload = x;
return msg;

So to apply this, you put a function node connected to the output of the temperature and put that code in it.

then put a debug node and make sure you are seeing what you want.

Use a change node like this:

[
    {
        "id": "0e398e3493950569",
        "type": "change",
        "z": "7fd8fff652f013f7",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$formatNumber(payload/10, '0.0')",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 850,
        "y": 2180,
        "wires": [
            [
                "aea1d39be7f0be03"
            ]
        ]
    }
]

Works perfect :slight_smile:

Thanks for quick response to a NOOB question.

What do you want 21 converted to?

If you want that to go to 2.1 then that function will not do that, it will convert it to 2.
Either way you don't need a function node, you can use the built in Range node.

image

If you only want integers out then tick the Round to nearest integer checkbox.

Nice
I like this one.

Thanks

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