# How to disgard NaN messages

**URL:** <https://discourse.nodered.org/t/how-to-disgard-nan-messages/48329>\
**Category:** General\
**Created:** [12 July 2021 18:00 UTC](https://discourse.nodered.org/t/how-to-disgard-nan-messages/48329 "2021-07-12T18:00:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaxSchaaper](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxschaaper/32/37608_2.png) [@MaxSchaaper](https://discourse.nodered.org/u/MaxSchaaper)\
**Post date:** [12 July 2021 18:00 UTC](https://discourse.nodered.org/t/how-to-disgard-nan-messages/48329/1 "2021-07-12T18:00:37Z")

</div>

A readout of my energy Smart meter gives me different values. Sometimes it gives a NaN value and sometimes the real value of the Gas-meter. How do I change my fow to disguard the NaN values and only let the real values pass.

[flows.json](https://discourse.nodered.org/uploads/short-url/1wlV9T7HT5GzZsQ29K0NwhmDW13.json) (2.2 KB)

Thanks for a reply.

---

<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:** [12 July 2021 18:10 UTC](https://discourse.nodered.org/t/how-to-disgard-nan-messages/48329/2 "2021-07-12T18:10:31Z")

</div>

A quick easy solution is to use [isNaN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN) in a function node...

```auto
if(isNaN(msg.payload)) {
  return null; //halt flow
}
return msg;

```

Note, isNaN expects a number.

---

<div class="post-metadata">

**Author:** ![MaxSchaaper](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxschaaper/32/37608_2.png) [@MaxSchaaper](https://discourse.nodered.org/u/MaxSchaaper)\
**Post date:** [12 July 2021 18:52 UTC](https://discourse.nodered.org/t/how-to-disgard-nan-messages/48329/4 "2021-07-12T18:52:27Z")

</div>

Thank you Steve, it works just fine.👍

---

<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:** [12 July 2021 19:20 UTC](https://discourse.nodered.org/t/how-to-disgard-nan-messages/48329/5 "2021-07-12T19:20:16Z")

</div>

Does using a Switch node to test for `is of type` Number reject NaN? I can't test it at the moment. If so then that could be used to pass only good numbers.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd5ccd826dc4473a9107ccd100c12ba1d5f2d41b.png)

---

<div class="post-metadata">

**Author:** ![MaxSchaaper](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maxschaaper/32/37608_2.png) [@MaxSchaaper](https://discourse.nodered.org/u/MaxSchaaper)\
**Post date:** [12 July 2021 19:47 UTC](https://discourse.nodered.org/t/how-to-disgard-nan-messages/48329/6 "2021-07-12T19:47:38Z")

</div>

That does not work because NaN is also of type number. The sollution Steve gave does work.

---

<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:** [12 July 2021 20:45 UTC](https://discourse.nodered.org/t/how-to-disgard-nan-messages/48329/7 "2021-07-12T20:45:33Z")

</div>

> [@MaxSchaaper](#):
>
> That does not work because NaN is also of type number.

I did wonder whether that would be the case. So NaN is a Number and is Not a Number at the same time!

---

<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:** [26 July 2021 20:46 UTC](https://discourse.nodered.org/t/how-to-disgard-nan-messages/48329/8 "2021-07-26T20:46:30Z")

</div>

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