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

public static Double getAttributeValueAsDouble(Node node, String attributeName, Double defaultValue) {
    final Node attributeNode = node.getAttributes().getNamedItem(attributeName);
    return attributeNode != null ? Double.parseDouble(attributeNode.getTextContent()) : defaultValue;
}

From source file:Main.java

public static Double[] stringToDoubleArr(String str, String delimeter) {
    String[] strArr = str.split(delimeter);
    Double[] doubleArr = new Double[strArr.length];
    for (int i = 0; i < strArr.length; i++) {
        doubleArr[i] = Double.parseDouble(strArr[i]);
    }/*from   ww w .j a  va2s. c om*/
    return doubleArr;
}

From source file:Main.java

public static double readDoubleFromEditText(EditText mEditText) {
    String payString = mEditText.getText().toString();

    double payDouble = 0.0;
    if (payString.length() > 0)
        payDouble = Double.parseDouble(payString);
    return payDouble;
}

From source file:Main.java

/**
 *
 * @param number//from   ww  w. j av a2 s  . c  om
 * @return
 */
public static Double convertStringToDoubleObject(String number) {

    if (number == null || number.isEmpty()) {
        return null;
    }
    try {
        return Double.parseDouble(number);
    } catch (NumberFormatException e) {
        return null;
    }
}

From source file:Main.java

public static String formatWithDecimal(String price) {
    return formatWithDecimal(Double.parseDouble(price));
}

From source file:Main.java

public static double getDoubleFromString(String number) {
    if (number.length() <= 0) {
        return 0;
    } else {/* www .  ja v  a 2 s .  c  o  m*/
        try {
            double num = Double.parseDouble(number);
            return num;
        } catch (Exception ex) {
            Log.e("Helper", ex.getMessage());
            return 0;
        }

    }
}

From source file:Main.java

public static String getSignedOddValue(String string) {

    if (string == null) {
        return "0";
    }//from  w ww. ja  v  a2 s.c om

    if (string.equals(""))
        return "";

    if (string.equals("-"))
        return "-";

    if (Double.parseDouble(string) > 0) {
        return "+" + string;
    } else {
        return string;
    }

}

From source file:Main.java

public static Double getDouble(JTextField txt, Double defaultVal) {
    String str = txt.getText();/*from   www .  j av a  2s.com*/
    if (str.trim().length() <= 0)
        return defaultVal;

    double val = 0;
    try {
        val = Double.parseDouble(str);
    } catch (NumberFormatException ex) {
    }
    return new Double(val);
}

From source file:Main.java

public static String getDecimalString(String value) {

    try {/* w w  w. j a  va  2  s  . c o m*/
        double result = Double.parseDouble(value); // Make use of autoboxing.  It's also easier to read.
        String output = decimalFormat.format(result);
        return output;
    } catch (NumberFormatException e) {
        // value did not contain a valid double
        return "";
    }
    //        return "" + (value != null ? decimalFormat.format(value) : "");
}

From source file:Main.java

/**
 * //  ww  w .  ja va 2 s  . co m
 * @param variation
 * @return
 */
public static double parseVariation(String variation) {
    double var = 0;
    if ((null == variation) || (variation.length() < 3)) {
        return 0;
    } else {
        var = Double.parseDouble(variation.substring(0, 2));
        if (variation.contains("E")) {
            var = -var;
        }
    }
    return var;
}