title: How do I check whether a double variable has more than two decimals in Java?
body: <p>I thought I could accomplish this easily with something such as the following:</p>
  
  <pre><code>double numInput;
  
  numInput = Double.parseDouble(inputTxtField.getText());
  
  if ((numInput * 100) % 1 != 0) {
  
  // do something
  
  }
  </code></pre>
  
  <p>However, I'm getting all sorts of strange test cases where such as:</p>
  
  <blockquote>
    <p>false:
    2.11,
    2.5,
    2.6</p>
    
    <p>true:
    2.22, 2.3, 2.2</p>
  </blockquote>
  
  <p>I just started programming so maybe this is a silly goof, but I thought multiplying a double by 100 and then checking for a remainder when dividing by 1 would work. The intent is to prevent someone from entering a number with more than two decimals. Less than or equal to 2 decimals is fine.</p>
  
  <p>Any tips are appreciated! Thank you!</p>
  
  <p>EDIT: Thank you for all the quick comments! This solved my problem, and I really appreciate the extra information as to why it won't work. Thank you!</p>