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 getProgress(int progress) {
    double temp = progress * 1.0;
    double pro = temp / 1024 / 1024;
    DecimalFormat df = new DecimalFormat("######0.00");
    return Double.parseDouble(df.format(pro));
}

From source file:Main.java

public static Double doubleFromStringOrDouble(Object stringOrDouble) {
    if (stringOrDouble == null) {
        return 0.0;
    } else if (stringOrDouble instanceof String) {
        try {/* w ww.  ja  v  a 2 s .com*/
            return Double.parseDouble((String) stringOrDouble);
        } catch (Exception e) {
            return 0.0;
        }
    } else if (stringOrDouble instanceof Double) {
        return (Double) stringOrDouble;
    } else {
        return 0.0;
    }
}

From source file:Main.java

public static String BTC2Fiat(String btc) {
    double val = 0.0;

    try {/*w  w  w .  j ava  2s.c o  m*/
        val = Double.parseDouble(btc);
    } catch (NumberFormatException nfe) {
        val = 0.0;
    }

    DecimalFormat df = new DecimalFormat("######0.00");
    return df.format(BTC2Fiat(val));
}

From source file:Main.java

/**
 * Parses the double./*from  www  .j av  a  2  s. co  m*/
 * 
 * @param str
 *            the str
 * @return the double
 */
public static double parseDouble(String str) {
    if (str == null) {
        str = "0";
    }
    return Double.parseDouble(str);
}

From source file:Main.java

public static boolean validatePhone(String phone) {

    try {//  w w w.  jav  a 2 s.  c o  m
        if (phone.trim().length() == 0) {
            return false;
        }
        double n = Double.parseDouble(phone);
        if (!(phone.trim().toString().startsWith("7") || phone.trim().toString().startsWith("8")
                || phone.trim().toString().startsWith("9")))
            return false;
        if (phone.trim().length() == 10)
            return true;

    } catch (Exception e) {
        return false;
    }
    return false;
}

From source file:Main.java

public static String Fiat2BTC(String fiat) {
    double val = 0.0;

    try {//from   w w w.  j av  a 2 s .  co  m
        val = Double.parseDouble(fiat);
    } catch (NumberFormatException nfe) {
        val = 0.0;
    }

    DecimalFormat df = new DecimalFormat("####0.0000");
    return df.format(Fiat2BTC(val));
}

From source file:Main.java

public static String addCommasToStringNumber(String number) {

    double num = 0;
    DecimalFormat formatter;/*from  w w w.  j av  a  2s  .co m*/

    try {
        num = Double.parseDouble(number);
        formatter = new DecimalFormat("#,###");
    } catch (Exception e) {
        return number;
    }

    return formatter.format(num);
}

From source file:Main.java

public static double doDouble(Object obj, double defValue) {
    return obj != null ? Double.parseDouble(obj.toString()) : defValue;
}

From source file:Main.java

public static String convertToDecimal(String val) {

    String convertedValue = "";

    try {/*from ww w  . ja v a  2 s  .  c  o m*/
        DecimalFormat df = new DecimalFormat("0.00");
        convertedValue = df.format(Double.parseDouble(val));
        df.setMaximumFractionDigits(2);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    return convertedValue;
}

From source file:Main.java

public static final double objectToDouble(Object o) {
    if (o instanceof Number)
        return ((Number) o).doubleValue();
    try {//from  w  ww . j  ava  2  s.  com
        if (o == null)
            return -1D;
        else
            return Double.parseDouble(o.toString());
    } catch (NumberFormatException e) {
        e.printStackTrace();
        return -1D;
    }
}