# How to convert a number that is 0 to a decimal 0.0?

**URL:** <https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289>\
**Category:** General\
**Created:** [3 September 2022 10:50 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289 "2022-09-03T10:50:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 10:50 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/1 "2022-09-03T10:50:19Z")

</div>

Hi,

I have looked at many posts on here but cannot find the answer.

I have a counter that resets to a number 0 at midnight.  
But my graph requires it as decimal 0.0

How do i convert and keep it a as a **decimal number** 0.0 ?

Thanks

---

<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:** [3 September 2022 11:09 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/2 "2022-09-03T11:09:08Z")

</div>

In JavaScript there is no difference. If what you have doesn't work then are you sure that what you have is not a string "0". Feed it into debug node and see what it says.

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 11:23 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/3 "2022-09-03T11:23:26Z")

</div>

Hi Colin,

I did look at many of your answers on here , before posting 😃

The number is definitely a number as it is sent from Node-RED to my database and it shows it as a number 0 in my database.

The problem is I use Grafana for my chart and unless the number is 0.0  
I get no graph.

If I manually change the database number to 0.0 the graph works perfectly.

So I need to make Node-RED send it as a decimal 0.0

Node-red sends all number as decimal numbers perfectly to my database, except 0.0 ?

Thanks

---

<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:** [3 September 2022 11:41 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/4 "2022-09-03T11:41:02Z")

</div>

What database type is it and what type is the field containing the value?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 September 2022 11:50 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/5 "2022-09-03T11:50:46Z")

</div>

> [@Colin](#):
>
> Feed it into debug node and see what it says.

Show us the result.

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 11:59 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/6 "2022-09-03T11:59:35Z")

</div>

Here is a test flow ...

```auto
[
    {
        "id": "824b0d3e2647818d",
        "type": "inject",
        "z": "9ae732bd.ba304",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0.00",
        "payloadType": "num",
        "x": 340,
        "y": 410,
        "wires": [
            [
                "e53c35c601d6c4d8"
            ]
        ]
    },
    {
        "id": "4563c529d740275f",
        "type": "debug",
        "z": "9ae732bd.ba304",
        "name": "MSG 02",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 470,
        "wires": []
    },
    {
        "id": "68fed087146b000e",
        "type": "inject",
        "z": "9ae732bd.ba304",
        "name": "For testing ... reset to 0",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "str",
        "x": 390,
        "y": 470,
        "wires": [
            [
                "ba818ad66ae3cdcb",
                "810b350e78143503"
            ]
        ]
    },
    {
        "id": "ba818ad66ae3cdcb",
        "type": "function",
        "z": "9ae732bd.ba304",
        "name": "Str > Num",
        "func": "msg.payload = Number(msg.payload);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 610,
        "y": 470,
        "wires": [
            [
                "4563c529d740275f"
            ]
        ]
    },
    {
        "id": "810b350e78143503",
        "type": "debug",
        "z": "9ae732bd.ba304",
        "name": "MSG - 03",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 530,
        "wires": []
    },
    {
        "id": "e53c35c601d6c4d8",
        "type": "debug",
        "z": "9ae732bd.ba304",
        "name": "MSG 01",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 410,
        "wires": []
    }
]

```

and this is how it looks in the SQLite JSON database

![31](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/8/18569df70a06c7a515c723efe8f8f34f3f082a9f.png)

and my setup

 ![32](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/38f00b3cd45550c8d2c4d19f8dfe4c619c032e08.jpeg)

Thanks

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 September 2022 12:07 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/7 "2022-09-03T12:07:58Z")

</div>

Although you have not posted the picture requested, your flow does have this:

 ![Untitled 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/7/e73a19dadbf7cdb13c67bfa077c7b63e635ec9e6.jpeg)  
Which strongly suggests that you are dealing with "0" not 0.

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 12:10 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/8 "2022-09-03T12:10:35Z")

</div>

Hi,

Yes i created this 'meter reading' years ago and i have it set as a string variable that is Global, that's why I convert from string to number.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 September 2022 12:30 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/9 "2022-09-03T12:30:17Z")

</div>

OK I understand if it's emulating an historical data point.  
Yes it comes out in debug as a number.

Sorry I don't have SQLite but if I was defining a Mariadb schema I would have discrete fields like this.

```auto
create table `foobar` (
`iso` datetime not null,  
`cost` float,  
`location` varchar(32),  
`meter_reading` float, 
primary key (`iso`)
 );

```

Your schema looks like everything is packed into a text field? I have no idea of the effect of that.

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 12:34 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/10 "2022-09-03T12:34:46Z")

</div>

Hi

Yes I agree it is text SQLite is limited,I think I will ask on Grafana forum.  
To be honest I would expect there chart to accept 0 as a feasible number for a chart, I just thought it would be easier to change in Node-RED  
😔

Not Node-RED's fault, maybe I am doing something wrong in Grafana, it's all new to me, but fun to see all my other graphs working.

Thanks for your help.

---

<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:** [3 September 2022 16:29 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/11 "2022-09-03T16:29:18Z")

</div>

Show us what is actually in the database for the 0 and 0.0 case, by running a query on the database to show it.

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 16:47 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/12 "2022-09-03T16:47:53Z")

</div>

Hi Colin,

I have limited knowledge with SQLite so I only know how to do this in DB Browser for SQLite, hope this is what you need ?

 ![34](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/2/32087a1fa0ef575145b21890aaa3cc0ef8c382ae.jpeg)

---

<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:** [3 September 2022 16:49 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/13 "2022-09-03T16:49:37Z")

</div>

What does it look like when there are numbers?

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 16:50 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/14 "2022-09-03T16:50:44Z")

</div>

![35](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/7/c760194653c000104ad96e54e4bd96233514ee5e.jpeg)

---

<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:** [3 September 2022 16:53 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/15 "2022-09-03T16:53:49Z")

</div>

What query are you running in Grafana?  
What happens in Grafana if you have some numbers and some 0 in the same window?

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 16:59 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/16 "2022-09-03T16:59:22Z")

</div>

```auto
select json_extract ( DATA,'$.meter_reading' ) as meter_reading,
		json_extract ( DATA,'$.iso') as time
from Energy
where DEVICE = 'IP15' ;

```

If my dataset starts with 0 i get a line on chart and everything is at 0

 ![36](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d1397c899b72685673a01e7ea7567e876c926c60.png)

If I do manually change in the database to 0.0 all works.

 ![37](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/6/c6566c7ca0c5bfbcb35cc0b0b951de9a692f0caa.png)

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 17:00 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/17 "2022-09-03T17:00:57Z")

</div>

Workaround for Grafana not displaying a graph if it gets 0 at start.  
( It will work with 0.0 if I change it manually in database ? ).

I think it needs a float number for reference at the start of reading from SQLite JSON database.  
as SQLite using JSON stores values in a text field.

I do have a workaround for it, but I don't like it, but I think it will work

```auto
msg.payload = Number(msg.payload);
msg.payload = msg.payload + .001; 
return msg;

```

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 17:03 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/18 "2022-09-03T17:03:49Z")

</div>

![38](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/64e606120759542bf00a946bf7bb548f943de3eb.png)

---

<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:** [3 September 2022 17:07 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/19 "2022-09-03T17:07:33Z")

</div>

Why does the second one have a different title? Also why does the second one not have a left axis?

---

<div class="post-metadata">

**Author:** ![questuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/questuk/32/4059_2.png) [@questuk](https://discourse.nodered.org/u/questuk)\
**Post date:** [3 September 2022 17:09 UTC](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289/20 "2022-09-03T17:09:53Z")

</div>

The 1st one is my test bed dashboard for fault finding.

The 2nd is my actual working Dashboard with the 0.0 added into my database manually as the very 1st entry.

Visually they are slightly different but underneath they are the same.

[Next page](https://discourse.nodered.org/t/how-to-convert-a-number-that-is-0-to-a-decimal-0-0/67289.md?page=2)
