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

/**
 * @param value//  ww w  .ja  va  2  s  .c  om
 * @return
 */
public static boolean isNumeric(String value) {

    try {
        Double.parseDouble(value);
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static double formatStringToDouble(String data) {
    try {//  w  w w  .  j a  v a2  s . co m
        return Double.parseDouble(data);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0.0;
}

From source file:Main.java

public static int getFormatDoubleIntValye(Object o) {
    try {/*  ww w.j a  v a 2 s  . c  o  m*/
        double v = (o != null && !o.toString().equals("")) ? Double.parseDouble(o.toString()) : 0;
        return (int) v;
    } catch (Exception ex) {
        return 0;
    }
}

From source file:Main.java

public static boolean isPositiveInteger(String numStr) {
    if (isInteger(numStr)) {
        double parseDouble = Double.parseDouble(numStr);
        if (parseDouble > 0) {
            return true;
        }//  ww w  . j a  va2s . c o  m
    }
    return false;
}

From source file:Main.java

public static String temperatureDoubleToString(String temperature) {
    int intTemperature = (int) Double.parseDouble(temperature);
    return Integer.toString(intTemperature);
}

From source file:Main.java

public static double getDoubleValue(Element ele, String tagName) {
    return Double.parseDouble(getTextValue(ele, tagName));
}

From source file:Main.java

public static String convertToCurrencyFormat(String amount) {
    double amountDouble = Double.parseDouble(amount);
    NumberFormat formatter = NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
    String returnString = formatter.format(amountDouble).replace("Rs.", "");
    return returnString.replace("Rs", "").trim();
}

From source file:Main.java

public static String sec2mi(String sec) {

    String mi = null;/*from   w w  w .j  ava 2s .com*/
    if (sec == null) {
        mi = "00 : 00";
    } else if (Double.parseDouble(sec) > 60) {
        mi = (int) Double.parseDouble(sec) / 60 + " : " + (int) Double.parseDouble(sec) % 60;
    } else {
        mi = "00 : " + (int) Double.parseDouble(sec);
    }
    return mi;
}

From source file:Main.java

public static double getDoubleTextField(double defaultValue, JTextComponent c) {
    try {/*from w w  w. j a  v  a2  s  . co  m*/
        return Double.parseDouble(c.getText());
    } catch (RuntimeException re) {
        return defaultValue;
    }
}

From source file:Main.java

public static double getStrength(String[] word) {
    double result = 0.0;
    for (int i = 0; i < word.length; i++) {
        result = result + (Double.parseDouble(word[i])) * (Double.parseDouble(word[i]));
    }//from   w w w  . j ava  2s. c om
    return Math.sqrt(result);
}