title: Java method returns double | int
body: <p>I need a method that will accept String number as a parameter and return double if it has a remainder, or int if it is decimal.</p>
  
  <p>I wrote such code:</p>
  
  <pre><code> private double convertToNumber(String number) {
      double d = Double.parseDouble(number);
      if (d % 1.0 == 0) {
          return Integer.parseInt(number);
      } else {
          return d;
      }
  }
  </code></pre>
  
  <p>but as signature of this method is double it returns double in any case.</p>
  
  <p>Please give me some hint.</p>