/** * For a string containing a number as judged by <code>isNumber()</code>, return the numerical value, rounded to an integer. * * @param string * string * @return the numeric value, rounded to an integer, or 0 if the string is not a valid number. */ public static int getNumber(String string) { String s = string.trim(); if (!isNumber(s)) return 0; double value = 0; try { value = Double.parseDouble(s); } catch (NumberFormatException e) { // logger.warn("Unexpected number value `" + s + "'"); } return (int) Math.round(value); }
/** * For a string containing a number as judged by <code>isNumber()</code>, return the numerical value, rounded to an integer. * * @param string * string * @return the numeric value, rounded to an integer, or 0 if the string is not a valid number. */ public static int getNumber(String string) { String s = string.trim(); if (!isNumber(s)) return 0; double value = 0; try { value = Double.parseDouble(s); } catch (NumberFormatException e) { // logger.warn("Unexpected number value `" + s + "'"); } return (int) Math.round(value); }