List of utility methods to do Number Parse
Number | toNumber(CharSequence jsonText) To number Number value = null; if (value == null) try { value = Integer.parseInt(jsonText.toString()); } catch (NumberFormatException e) { if (value == null) try { ... |
Number | toNumber(final Object obj) to Number try { if (obj instanceof String) { return Double.valueOf((String) obj); } else if (obj instanceof Number) { return (Number) obj; } else { throw new IllegalArgumentException("Could not convert value to number: " + obj); } catch (Exception e) { throw new IllegalArgumentException("Could not convert value to number: " + obj, e); |
Number | toNumber(Object object, Number defaultValue) Extract the value represented by the given object (Number or String) - trialing '.0*' will be removed. if (object == null) { return defaultValue; if (object instanceof Number) { return (Number) object; String s = object.toString(); s = s.replaceAll("\\.0*$", ""); ... |
Number | toNumber(Object object, Number defaultValue) to Number if (object == null) { return defaultValue; if (object instanceof Number) { return (Number) object; String s = object.toString(); s = s.replaceAll("\\.0*$", ""); ... |
Long | toNumber(String hash) Decodes the String provided which should represent a hexadecimal number into a Long . return (hash == null) ? null : Long.decode("0x" + hash); |
Number | toNumber(String num) to Number if (num == null || num.length() < 1) return null; if (num.contains(".")) { return Double.parseDouble(num); } else { return Integer.parseInt(num); |
int | toNumber(String s) to Number return Integer.valueOf(s);
|
String | toNumber(String string) to Number char[] stringArray = string.toCharArray(); StringBuilder number = new StringBuilder(); for (char ch : stringArray) { if (ch >= '0' && ch <= '9') { number.append(ch); return number.toString(); ... |
Number | toNumber(String text) Parses a JSON formatted number from text. if (text == null) { return null; boolean fp = false; for (char c : text.toCharArray()) { if (c == '.' || c == 'e' || c == 'E') { fp = true; break; ... |
int | toNumber(String value, int defValue) Convenience method for converting a String into an Integer. if (value != null) { try { return Integer.parseInt(value); } catch (NumberFormatException e) { return defValue; |