List of usage examples for java.lang Double parseDouble
public static double parseDouble(String s) throws NumberFormatException
From source file:Main.java
public static double getDoubleFrom(CharSequence chars) { double val = 0; if (!"".equals(chars.toString())) { val = Double.parseDouble(chars.toString()); }/*from ww w .j a va2 s .com*/ return val; }
From source file:Main.java
/** * Parses the supplied xsd:double string and returns its value. * /* w w w . ja v a 2 s.c o m*/ * @param s * A string representation of an xsd:double value. * @return The <tt>double</tt> value represented by the supplied string * argument. * @throws NumberFormatException * If the supplied string is not a valid xsd:double value. */ public static double parseDouble(String s) { s = trimPlusSign(s); return Double.parseDouble(s); }
From source file:Main.java
private static Object convertValType(Object value, Class<?> fieldTypeClass) { Object retVal;// w w w .j av a 2s. c om if (Long.class == fieldTypeClass || long.class == fieldTypeClass) { retVal = Long.parseLong(value.toString()); } else if (Integer.class == fieldTypeClass || int.class == fieldTypeClass) { retVal = Integer.parseInt(value.toString()); } else if (Float.class == fieldTypeClass || float.class == fieldTypeClass) { retVal = Float.parseFloat(value.toString()); } else if (Double.class == fieldTypeClass || double.class == fieldTypeClass) { retVal = Double.parseDouble(value.toString()); } else { retVal = value; } return retVal; }
From source file:Main.java
/** * Get value of specified attribute as double. If attribute isn't defined return defValue. * @param attribs NamedNodeMap//w ww .j a va 2 s . co m * @param attributeName String * @param defValue double * @return double * @throws DOMException */ public static double getAttributeValueAsDouble(NamedNodeMap attribs, String attributeName, double defValue) throws DOMException { String v = getAttributeValue(attribs, attributeName); double result = defValue; if (v != null) { try { result = Double.parseDouble(v); } catch (NumberFormatException ex) { } } return result; }
From source file:Main.java
static public double getDoubleTextContent(Element element) { return Double.parseDouble(getTrimmedTextContent(element)); }
From source file:Main.java
public static Double number(Element context, String expression, double defaultValue) { String value = string(context, expression); if (value == null) return defaultValue; return Double.parseDouble(value); }
From source file:Main.java
/** * Convert input String to JSONObject, JSONArray, or String * * @param str/*from w w w . j a v a2 s .c o m*/ * JSON data in string format * * @return JSONArray or JSONObject or String */ static Object stringToJSON(String str) { try { return new JSONArray(str); } catch (JSONException e) { } try { return new JSONObject(str); } catch (JSONException ex) { } try { return Integer.parseInt(str); } catch (Exception ex) { } try { return Double.parseDouble(str); } catch (Exception ex) { } return str; }
From source file:Main.java
/** * Gets the node value as double./*w w w. j ava 2 s . co m*/ * *@param node Description of the Parameter *@return The nodeValueAsDouble value *@exception DOMException Description of the Exception */ public final static double getNodeValueAsDouble(Node node) throws DOMException { if (node != null) { node = node.getFirstChild(); if (node != null) return Double.parseDouble(node.getNodeValue()); } return -1; }
From source file:Main.java
public static Double getTotalWeightFromNBestLine(String nBestLine) { int firstIndexWeightSubstring = nBestLine.lastIndexOf(JOSHUA_SEPARATOR) + JOSHUA_SEPARATOR.length(); String weightSubstring = nBestLine.substring(firstIndexWeightSubstring); return Double.parseDouble(weightSubstring); }
From source file:Main.java
public static String decodeGpsAddress(String name, double coords[]) { /*/*from w w w . j a va 2 s . co m*/ * Match predictable GPS pattern of DDMMSS[N|S]DDDMMSS[E|W] */ Matcher m = ICAO_GPS_PATTERN.matcher(name); if (m.matches()) { String label; try { label = m.group(1) == null ? "" : m.group(1); double lat_deg = Double.parseDouble(m.group(3)), lat_min = Double.parseDouble(m.group(4)), lat_sec = Double.parseDouble(m.group(5)), lat_south = m.group(6).equalsIgnoreCase("S") ? -1 : 1, lon_deg = Double.parseDouble(m.group(7)), lon_min = Double.parseDouble(m.group(8)), lon_sec = Double.parseDouble(m.group(9)), lon_west = m.group(10).equalsIgnoreCase("W") ? -1 : 1; coords[0] = lon_west * truncGeo(lon_deg + lon_min / 60.0 + lon_sec / (60.0 * 60.0)); coords[1] = lat_south * truncGeo(lat_deg + lat_min / 60.0 + lat_sec / (60.0 * 60.0)); } catch (Exception e) { return null; } /* * Sane input */ if ((!isLatitudeSane(coords[1])) || (!isLongitudeSane(coords[0]))) { return null; } return label; } else if (name.contains("&")) { String token[] = new String[2]; token[1] = token[0] = name; if (name.contains("@")) { /* * This could be the geo point from maps */ token = name.split("@"); } /* * This is lon/lat destination */ String tokens[] = token[1].split("&"); try { coords[0] = Double.parseDouble(tokens[1]); coords[1] = Double.parseDouble(tokens[0]); } catch (Exception e) { return null; } /* * Sane input */ if ((!isLatitudeSane(coords[1])) || (!isLongitudeSane(coords[0]))) { return null; } return token[0]; } return null; }