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 boolean decimal(Object o) {
    double n = 0;
    try {/*from   w w w .j av  a2 s  .  c om*/
        n = Double.parseDouble(o.toString().trim());
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    if (n > 0.0) {
        return true;
    } else {
        return false;
    }
}

From source file:Main.java

public static double getBigDecimal_0(String strings) {
    double price = Double.parseDouble(strings);
    BigDecimal bg = new BigDecimal(price).setScale(0, BigDecimal.ROUND_UP);
    return bg.doubleValue();
}

From source file:Main.java

public static double getBigDecimal_6(String strings) {
    double price = Double.parseDouble(strings);
    BigDecimal bg = new BigDecimal(price).setScale(6, BigDecimal.ROUND_UP);
    return bg.doubleValue();
}

From source file:Main.java

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

From source file:Main.java

public static Number string2number(final String iText) {
    if (iText.indexOf('.') > -1)
        return Double.parseDouble(iText);
    else//from   www.  j  a va2  s . c  om
        return Long.parseLong(iText);
}

From source file:Main.java

public static double getConvertDouble(String str) {
    double i = 0;
    try {//from w  ww . java 2 s . c  om
        i = Double.parseDouble(str);
    } catch (Exception e) {
        i = 0;
    }

    return i;
}

From source file:Main.java

public static double getDouble(String string, double fallBack) {
    double d;//from   www.  ja v a 2  s . c  o  m
    try {
        d = Double.parseDouble(string);
    } catch (Exception e) {
        d = fallBack;
    }
    return d;
}

From source file:Main.java

public static String keepZeroSecimal(String numberStr) {
    double number = Double.parseDouble(numberStr);
    BigDecimal b = new BigDecimal(number);

    String ss = b.setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue() + "";

    return ss;//from   w  w  w .j a  v  a  2  s  . c o  m
}

From source file:Main.java

public static boolean isNumeric(String str) {
    try {/*www.  ja v  a  2 s.c  o m*/
        @SuppressWarnings("unused")
        double d = Double.parseDouble(str);
    } catch (NumberFormatException nfe) {
        return false;
    }
    return true;
}

From source file:Main.java

public static String keepNSecimal(String numberStr, int n) {
    double number = Double.parseDouble(numberStr);
    BigDecimal b = new BigDecimal(number);
    String ss = b.setScale(n, BigDecimal.ROUND_HALF_UP).doubleValue() + "";
    int pointIndex = ss.lastIndexOf(".");
    int fractionCount = ss.length() - pointIndex - 1;
    for (int i = 0; i < n - fractionCount; i++) {
        ss += 0;/*from   ww  w.j  a  v a  2 s .  c  o  m*/
    }
    return ss;
}