Example usage for java.lang Double parseDouble

List of usage examples for java.lang Double parseDouble

Introduction

In this page you can find the example usage for java.lang Double parseDouble.

Prototype

public static double parseDouble(String s) throws NumberFormatException 

Source Link

Document

Returns a new double initialized to the value represented by the specified String , as performed by the valueOf method of class Double .

Usage

From source file:Main.java

/**
 * Parses the given string and returns a double value. Returns null if the
 * given string is null or cannot be parsed as a double.
 *
 * @param value the string value.//from  w  w  w.  jav  a 2s  .c  om
 * @return a double value.
 */
public static Double parseDouble(String value) {
    if (value == null || value.trim().isEmpty()) {
        return null;
    }

    try {
        return Double.parseDouble(value);
    } catch (NumberFormatException ex) {
        return null;
    }
}

From source file:Main.java

public static Double getAttributeValueAsDouble(Node node, String attributeName) {
    return Double.parseDouble(node.getAttributes().getNamedItem(attributeName).getTextContent());
}

From source file:Main.java

public static int findBestMotZoomValue(CharSequence stringValues, int tenDesiredZoom) {
    int tenBestValue = 0;
    for (String stringValue : COMMA_PATTERN.split(stringValues)) {
        stringValue = stringValue.trim();
        double value;
        try {//w ww.j  a  va2  s. com
            value = Double.parseDouble(stringValue);
        } catch (NumberFormatException nfe) {
            return tenDesiredZoom;
        }
        int tenValue = (int) (10.0 * value);
        if (Math.abs(tenDesiredZoom - value) < Math.abs(tenDesiredZoom - tenBestValue)) {
            tenBestValue = tenValue;
        }
    }
    return tenBestValue;
}

From source file:Main.java

public static double getEmuiVersion() {
    try {/* w ww. j  a  v a2 s .c o m*/
        String emuiVersion = getSystemProperty("ro.build.version.emui");
        String version = emuiVersion.substring(emuiVersion.indexOf("_") + 1);
        return Double.parseDouble(version);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 4.0;
}

From source file:Main.java

/**
 *  Gets the String value as double.//from   w  ww  .  j a  v a  2 s.  c o m
 */
public final static double getStringAsDouble(String value) {
    return value == null ? -1 : Double.parseDouble(value);
}

From source file:Main.java

/**
 * /*w  ww . j  a  v a2  s .  co  m*/
 * @param object
 * @return
 */
protected static Double toDouble(Object object) {
    String str = toString(object);
    if ("".equals(str))
        return 0.0;
    else
        return Double.parseDouble(str);
}

From source file:Main.java

/**
 * Safely converts an object into an double
 *
 * @param obj/* ww w  . j a  v  a  2  s.  c om*/
 *            The object to convert.
 * @return a Double representing the double value of the Object (null if the
 *         object cannot be converted to Double)
 */
public static Double safeJsonToDouble(Object obj) {
    Double doubleValue;

    try {
        doubleValue = Double.parseDouble(safeJsonToString(obj));
    } catch (NumberFormatException e) {
        doubleValue = null;
    }

    return doubleValue;
}

From source file:Main.java

public static String truncateChange(String change, boolean isPercentChange) {
    String weight = change.substring(0, 1);
    String ampersand = "";
    if (isPercentChange) {
        ampersand = change.substring(change.length() - 1, change.length());
        change = change.substring(0, change.length() - 1);
    }/* w w w . j  av  a  2  s . c  o m*/
    change = change.substring(1, change.length());
    double round = (double) Math.round(Double.parseDouble(change) * 100) / 100;
    change = String.format("%.2f", round);
    StringBuffer changeBuffer = new StringBuffer(change);
    changeBuffer.insert(0, weight);
    changeBuffer.append(ampersand);
    change = changeBuffer.toString();
    return change;
}

From source file:Main.java

public static String formatToStringWithoutDecimal(String value) {
    return formatToStringWithoutDecimal(Double.parseDouble(value));
}

From source file:Main.java

public static Double number(Element context, String expression) {
    String value = string(context, expression);
    if (value == null)
        return null;
    return Double.parseDouble(value);
}