title: Java,Double comparison , if ((BMI) >= 18.5 || (BMI) <= 24.9) , the condition is true while BMI=25.77777777777778
body: <p>This is just a simple Java code but gets a wrong result:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class BMI_Calculator {
  
      public static void main(String[] args) {
          Scanner s = new Scanner(System.in);
          System.out.print("Enter your weight(kg):");
          double w = s.nextDouble();
          System.out.printf("\n%s", "Enter you height(cm):");
          double h = s.nextDouble();
          h = h / 100;
  
          double BMI = w / (h * h);
  
          String b;
  
          if (BMI &lt; 18.5) {
              System.out.println("less than 18.5");
              b = "Underweight";
          } else if ((BMI) &gt;= 18.5 || (BMI) &lt;= 24.9) {
              System.out.println("between 18.5 and 24.9");
              b = "Normal";
          } else if (BMI &gt;= 25 || BMI &lt;= 29.9) {
              System.out.println("between 25 and 29.9");
              b = "Overweight";
          } else {
              System.out.println("greater than 30");
              b = "Obese";
          }
  
          System.out.println("Your BMI is:" + BMI + "(" + b + ")");
  
      }
  
  }
  </code></pre>
  
  <p>This is the output</p>
  
  <blockquote>
    <p>Enter your weight(kg):58</p>
    
    <p>Enter you height(cm):150</p>
    
    <p>between 18.5 and 24.9</p>
    
    <p>Your BMI is:25.77777777777778(Normal)</p>
  </blockquote>
  
  <p>I thought it might be related to precision of double variable, I tried the same code declaring the variables as float instead of double and got the same result , I really don't understand how could such a thing happen (25.7 &lt; 24.9)?! how?!</p>