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 String formatDecimal(String dec) {
    if (TextUtils.isEmpty(dec))
        return "";
    Double d = Double.parseDouble(dec);
    return String.format("%.1f", d);
}

From source file:Main.java

public static String liangweixiaoshu2(String value) {
    DecimalFormat df = new DecimalFormat("#.00");
    Double dValue = Double.parseDouble(value);
    return df.format(dValue);
}

From source file:Main.java

public static String formatDecimal(String dec) {
    if (TextUtils.isEmpty(dec)) {
        return "";
    }//from   ww w  .  ja v a  2  s . c o m
    Double d = Double.parseDouble(dec);
    return String.format("%.1f", d);
}

From source file:Main.java

public static double tryParseDouble(String text, double def) {
    double ret = 0.0;
    try {// www.  j a  va 2s  .c  om
        ret = Double.parseDouble(text);
    } catch (Exception e) {
        ret = def;
    }

    return ret;
}

From source file:Main.java

public static double parseDouble(String string, double defaultValue) {
    double rc = defaultValue;
    try {//  ww w. ja  va  2 s.c o  m
        if (string != null)
            rc = Double.parseDouble(string.trim());
    } catch (Throwable localThrowable) {
    }
    return rc;
}

From source file:Main.java

/**
 * removing comma and parse into 'double'
 * @param String value/*from w w  w  . j a  v a  2s. c  o m*/
 * @return Integer
 */
public static double removeDoubleComma(String value) {
    return Double.parseDouble(value.replaceAll(",", ""));
}

From source file:Main.java

/**
 * Str to double./* ww  w  .j a  v  a 2s  . co  m*/
 *
 * @param str the str
 * @return the double
 */
public static double strToDouble(String str) {

    try {
        return Double.parseDouble(str);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static double getXMLNum(Element e, String attrName) {
    try {/*from w w w .  ja v a 2  s. c  om*/
        return Double.parseDouble(e.getAttribute(attrName));
    } catch (Exception exc) {
        return 0;
    }
}

From source file:Main.java

public static double getSalesDone(String budget, String Sales) {
    DecimalFormat twoDForm = new DecimalFormat("#.##");

    double bud = Double.parseDouble(budget);
    double sale = Double.parseDouble(Sales);

    double result = (sale / bud) * 100;

    result = Double.valueOf(twoDForm.format(result));
    return result;

}

From source file:Main.java

public static String changeMoney(String pattern, String value) {
    double va = 0;
    try {/*from ww  w  . j a v  a  2  s.c om*/
        va = Double.parseDouble(value);
    } catch (Exception e) {
        return "";
    }
    DecimalFormat myFormatter = new DecimalFormat(pattern);
    myFormatter.applyPattern(pattern);
    return myFormatter.format(va);
}