code: public static int toInteger(Object value, EvaluationContext ctx) {
          if (value instanceof Boolean) {
              return ((Boolean) value) ? 1 : 0;
          }
          else if (value instanceof Integer) {
              return (Integer) value;
          }
          else if (value instanceof BigDecimal) {
              try {
                  return ((BigDecimal) value).setScale(0, RoundingMode.HALF_UP).intValueExact();
              }
              catch (ArithmeticException ex) {}
          }
          else if (value instanceof String) {
              try {
                  return Integer.parseInt((String) value);
              }
              catch (NumberFormatException e) {}
          }
  
          throw new EvaluationError("Can't convert '" + value + "' to an integer");
      }
docs: Tries conversion of any value to an integer