# parseFloat doesn't output zero values

**URL:** <https://discourse.nodered.org/t/parsefloat-doesnt-output-zero-values/64149>\
**Category:** General\
**Created:** [20 June 2022 04:09 UTC](https://discourse.nodered.org/t/parsefloat-doesnt-output-zero-values/64149 "2022-06-20T04:09:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [20 June 2022 04:09 UTC](https://discourse.nodered.org/t/parsefloat-doesnt-output-zero-values/64149/1 "2022-06-20T04:09:34Z")

</div>

I have this function receiving a stream of data from a script running an analog to digital converter.

```auto
var t=msg.payload;
if(t!=="")
{
k=t.split(':');
for (i = 0; i < k.length; i++)
{
    k[i]=parseFloat(k[i]);
}

msg.topic="Analogues";
	if(k[0]&&k[1]&&k[2]&&k[3]&&k[4]&&k[5]&&k[6]&&k[7]&&k[8])
		{
		msg.payload={"AP0":k[0],"AP1":k[1],"AP2":k[2],"AP3":k[3],"Ah":k[4],"InstP":k[5],"SOC4":k[6],"SOC3":k[7],"SOC5":k[8]};
		return msg;

    }
}

```

The function is working fine until any of the values in the stream of data is a 0.  
Then, if any of the values is a 0(zero), the function doesn't output anything.

This is the payload:

```auto
"26.443:3.296:0.749:1.000:0.010:19.815:100.01:100.01:100.01"

```

Since can happen that a specific value is just a 0, how can I solve this inconvenience?  
Any help will be appreciated.  
Thanks

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 June 2022 05:39 UTC](https://discourse.nodered.org/t/parsefloat-doesnt-output-zero-values/64149/2 "2022-06-20T05:39:41Z")

</div>

> [@FeliceM](#):
>
> `if(k[0]&&k[1]&&k[2]&&k[3]&&k[4]&&k[5]&&k[6]&&k[7]&&k[8])`

0 is falsey in JavaScript so this `if` clause will be skipped.

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [20 June 2022 06:11 UTC](https://discourse.nodered.org/t/parsefloat-doesnt-output-zero-values/64149/3 "2022-06-20T06:11:23Z")

</div>

Got it. Thanks

At the beginning of the cycle the script doesn't output all the values. This until all filters have stored enough values to start computing the output. So the first 10 second I have only a couple of variables with values.  
Removing the `if` would cause a lot of errors:

`Error: A 400 Bad Request error occurred: {"error":"unable to parse '102 AP0=26.486082000000003,AP1=undefined,AP2=undefined,AP3=undefined,Ah=undefined,InstP=undefined,SOC3=undefined,SOC4=undefined,SOC5=undefined': invalid boolean"}`

I need to find another way... However now I do understand better what is happening.  
Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 June 2022 06:16 UTC](https://discourse.nodered.org/t/parsefloat-doesnt-output-zero-values/64149/4 "2022-06-20T06:16:14Z")

</div>

If you know there must be (for example) 9 or more items then test the length of `k` immediately after the split.

```auto
if(k.length < 9) {
  return null;
}

```

---

<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:** [4 July 2022 06:16 UTC](https://discourse.nodered.org/t/parsefloat-doesnt-output-zero-values/64149/5 "2022-07-04T06:16:45Z")

</div>

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