# Create decimal value

**URL:** <https://discourse.nodered.org/t/create-decimal-value/59580>\
**Category:** General\
**Created:** [9 March 2022 10:06 UTC](https://discourse.nodered.org/t/create-decimal-value/59580 "2022-03-09T10:06:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Espene](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@Espene](https://discourse.nodered.org/u/Espene)\
**Post date:** [9 March 2022 10:06 UTC](https://discourse.nodered.org/t/create-decimal-value/59580/1 "2022-03-09T10:06:54Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [9 March 2022 10:12 UTC](https://discourse.nodered.org/t/create-decimal-value/59580/2 "2022-03-09T10:12:52Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [9 March 2022 10:15 UTC](https://discourse.nodered.org/t/create-decimal-value/59580/3 "2022-03-09T10:15:18Z")

</div>

Use a change node like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c9ef606b87b95c7b523e137467168c7c842d447e.png)

```auto
[
    {
        "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"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![Espene](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@Espene](https://discourse.nodered.org/u/Espene)\
**Post date:** [9 March 2022 10:15 UTC](https://discourse.nodered.org/t/create-decimal-value/59580/4 "2022-03-09T10:15:47Z")

</div>

Works perfect 🙂

Thanks for quick response to a NOOB question.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 March 2022 10:51 UTC](https://discourse.nodered.org/t/create-decimal-value/59580/5 "2022-03-09T10:51:54Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/64dac4db3b1a45418dc9f7f0c46d7351cffe7764.png)

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

---

<div class="post-metadata">

**Author:** ![Espene](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@Espene](https://discourse.nodered.org/u/Espene)\
**Post date:** [9 March 2022 11:48 UTC](https://discourse.nodered.org/t/create-decimal-value/59580/6 "2022-03-09T11:48:32Z")

</div>

Nice  
I like this one.

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 March 2022 11:49 UTC](https://discourse.nodered.org/t/create-decimal-value/59580/7 "2022-03-23T11:49:24Z")

</div>

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