title: How to convert a String to an Integer in Groovy
body: <p>How can I convert a String (which is a number) to integer in Groovy.
  I am using Groovy 2.4.5. Here is a sample code which throws exception:</p>
  
  <p>Code:</p>
  
  <pre><code>def String a = "CHECK";
  
  def String b = "3.5";
  def String c = "7.5";
  
  println "Is a number ? " + a.isNumber();
  println "Is b number ? " + b.isNumber();
  println "Is c number ? " + c.isNumber();
  
  if (a.equals("CHECK"))
  {
      def int x = b.toInteger();
      def int y = c.toInteger();
  }
  
  println b+c;
  </code></pre>
  
  <p>Output (with exceptions):</p>
  
  <pre><code>Is a number ? false
  Is b number ? true
  Is c number ? true
  Exception thrown
  
  java.lang.NumberFormatException: For input string: "3.5"
  
      at myAdditionLogic.run(myAdditionLogic.groovy:12)
  </code></pre>