Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a value is included between two other values?

I'm trying to express a condition like this:

if 33.75 < degree <= 56.25   # some code end 

But Ruby gives this error:

undefined method `<=' for true:TrueClass 

I'm guessing that one way to do it is something like:

if 33.75 < degree and degree <= 56.25   # code end 

But there is no another, easier way?

like image 900
Marc Pursals Avatar asked Sep 03 '13 15:09

Marc Pursals


People also ask

How do you check if a value is between two values?

For example, you need to check if value in cell B2 is between values in cell A2 and A3. Please apply the following formula to achieve it. 1. Select a blank cell which you need to display the result, enter formula =IF(AND(B2>A2,B2<A3),"Yes","No") into the Formula Bar and then press the Enter key.

How do you do an IF function between two numbers?

Step 1: Put the number you want to test in cell C6 (150). Step 2: Put the criteria in cells C8 and C9 (100 and 999). Step 3: Put the results if true or false in cells C11 and C12 (100 and 0). Step 4: Type the formula =IF(AND(C6>=C8,C6<=C9),C11,C12).

Is there a between function in Excel?

What is a BETWEEN function in Excel? A BETWEEN function or formula can tell you whether a number, date or other information, such as text, is between two given values in a dataset.

How do I use between conditions in Excel?

Excel formula: if between two numbers To test if a given number is between two numbers that you specify, use the AND function with two logical tests: Use the greater then (>) operator to check if the value is higher than a smaller number.


1 Answers

Ruby also has between?:

if value.between?(lower, higher)  
like image 99
nimrodp Avatar answered Sep 21 '22 06:09

nimrodp