# Switch between numeric values passes when value is true/false

**URL:** <https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971>\
**Category:** General\
**Created:** [20 August 2021 22:11 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971 "2021-08-20T22:11:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [20 August 2021 22:11 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/1 "2021-08-20T22:11:42Z")

</div>

Is this working as designed ? Should true/false pass ?

 ![Screenshot 2021-08-21 at 00.10.16](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ceb8e7204315cc2a0e3818aad9554c2fe13caf31.jpeg)

 ![.Screenshot 2021-08-21 at 00.09.37](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/767fa8577f5896644e73033d7ae9b32a553a6330.jpeg)

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [20 August 2021 23:40 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/2 "2021-08-20T23:40:12Z")

</div>

> [@bakman2](#):
>
> Should true/false pass ?

~~Neither `true` or `false` are numbers~~ , thus probably passes through as extraneous data?

**EDIT** Actually, it is accounting for the binary "value" of the Boolean, AKA 1 or 0, as confirmed by changing the switch values from 0-255 to 1-255, thus preventing `false` to pass

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [21 August 2021 04:15 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/3 "2021-08-21T04:15:26Z")

</div>

Yes that seems to happen here.

I have added an additional switch to make sure that the type matches numeric. I just wonder if this should be handled directly in the case of the "is between".

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [21 August 2021 05:04 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/4 "2021-08-21T05:04:47Z")

</div>

> [@bakman2](#):
>
> I just wonder if this should be handled directly in the case of the "is between".

I suspect it is the way it is meant to be, as there are surely many valid reasons for a `boolean` to be treated by it's numerical value. But if not desired to be treated equally then can easily be overcome with a preceding `switch` using the `is of type = number` filter ( ~~~as you have probably done~~~ EDIT as I reread and see that is exactly as you have done 😊 ).

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 August 2021 08:43 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/5 "2021-08-21T08:43:09Z")

</div>

> [@bakman2](#):
>
> I have added an additional switch to make sure that the type matches numeric

You could handle the bug using a JSONata expression and only use one switch node.

```auto
$type($$.payload) = "number" ? ($$.payload >= 0 and $$.payload <= 255) : false

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [21 August 2021 09:19 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/6 "2021-08-21T09:19:36Z")

</div>

I understand, but it defeats the purpose of the "is between" function 😉

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [21 August 2021 09:35 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/7 "2021-08-21T09:35:58Z")

</div>

IME true/false Booleans are processed as being equivalent to 1/0 99% of the time in 99% of languages and for 99% of the time this is what we want to happen 🙂

Occasionally, it doesn't work out, as in this case

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [21 August 2021 09:45 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/8 "2021-08-21T09:45:10Z")

</div>

> [@bakman2](#):
>
> but it defeats the purpose of the "is between" function

But does it? A Boolean is a binary choice, typically 0 (false) or 1(true), but can also mean 0 (false) and not-zero (true,1,2,3,4,5... infinity). Thus it really does fall "in between" 0 and infinity.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [21 August 2021 10:11 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/9 "2021-08-21T10:11:27Z")

</div>

Yes it does. There is no "is between true and false". It all depends on the intention behind the "is between" function, was it designed to make decisions between 2 numbers or was it meant capture the answers of the universe ? If the latter, soit. If not, it would perhaps be nice to exclude them.

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [21 August 2021 10:59 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/10 "2021-08-21T10:59:39Z")

</div>

> [@bakman2](#):
>
> Yes it does

My last view/say on this... It works just fine, and since only the inclusion of an (already) easily excludable boolean may affect "subjective perfection" then I still state that it doesn't really matter. But if the devs "fix" it or state it is intentional.... or say nothing, well... that is up to them 🙂

---

<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:** [20 October 2021 10:59 UTC](https://discourse.nodered.org/t/switch-between-numeric-values-passes-when-value-is-true-false/49971/11 "2021-10-20T10:59:43Z")

</div>

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