# Compare two numbers

**URL:** https://discourse.nodered.org/t/compare-two-numbers/53935
**Category:** General
**Created:** [18 November 2021 11:20 UTC](https://discourse.nodered.org/t/compare-two-numbers/53935 "2021-11-18T11:20:26Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Crabsticks](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crabsticks/32/94714_2.png) [@Crabsticks](https://discourse.nodered.org/u/Crabsticks)
#### Post date: [18 November 2021 11:20 UTC](https://discourse.nodered.org/t/compare-two-numbers/53935/1 "2021-11-18T11:20:26Z")

</div>

Hello,

A very basic noob question that I'm struggling to figure out.  
I have 2 payloads with numeric values and I need to compare them to find out which is larger at any given time.

I think this is done with the function node but writing the code is beyond me and I'm guessing this function has already been written but Google isn't turning up any results.

Can anyone point me in the right direction please

---

<div class="post-metadata">

### Author: ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)
#### Post date: [18 November 2021 11:22 UTC](https://discourse.nodered.org/t/compare-two-numbers/53935/2 "2021-11-18T11:22:35Z")

</div>

Welcome to the forums!  
There are lot's of examples here:

> **[JavaScript Tutorial](https://www.w3schools.com/js/DEFAULT.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

> **[JavaScript Comparison and Logical Operators](https://www.w3schools.com/js/js_comparisons.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

---

<div class="post-metadata">

### Author: ![Crabsticks](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crabsticks/32/94714_2.png) [@Crabsticks](https://discourse.nodered.org/u/Crabsticks)
#### Post date: [18 November 2021 11:31 UTC](https://discourse.nodered.org/t/compare-two-numbers/53935/3 "2021-11-18T11:31:42Z")

</div>

Thank you, but writing the code is beyond me sadly. I was hoping for something I could copy and paste

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [18 November 2021 11:33 UTC](https://discourse.nodered.org/t/compare-two-numbers/53935/4 "2021-11-18T11:33:42Z")

</div>

maybe this thread will help [Compare two values to generate a difference value](https://discourse.nodered.org/t/compare-two-values-to-generate-a-difference-value/46890)

---

<div class="post-metadata">

### Author: ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)
#### Post date: [18 November 2021 12:42 UTC](https://discourse.nodered.org/t/compare-two-numbers/53935/5 "2021-11-18T12:42:35Z")

</div>

Many thanks

---

<div class="post-metadata">

### Author: ![Crabsticks](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crabsticks/32/94714_2.png) [@Crabsticks](https://discourse.nodered.org/u/Crabsticks)
#### Post date: [18 November 2021 16:00 UTC](https://discourse.nodered.org/t/compare-two-numbers/53935/6 "2021-11-18T16:00:42Z")

</div>

hi,  
Thank you for the suggestions but I have figured out how to do it without code by using a change node to place one value into a variable then a switch node to compare that with the the second value

---

<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: [2 December 2021 16:01 UTC](https://discourse.nodered.org/t/compare-two-numbers/53935/7 "2021-12-02T16:01:07Z")

</div>

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