Example usage for java.lang Double valueOf

List of usage examples for java.lang Double valueOf

Introduction

In this page you can find the example usage for java.lang Double valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Double valueOf(double d) 

Source Link

Document

Returns a Double instance representing the specified double value.

Usage

From source file:Main.java

public static int formatDurationString(String durationString) {
    int duration = 0;
    if (durationString == null || durationString.length() == 0) {
        return duration;
    }//  w  w w .  ja  v  a  2  s.  c om

    try {
        String sArray[] = durationString.split(COLON);
        double hour = Double.valueOf(sArray[0]);
        double minute = Double.valueOf(sArray[1]);
        double second = Double.valueOf(sArray[2]);

        return (int) (((hour * 60 + minute) * 60 + second) * 1000);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return duration;
}

From source file:Main.java

public static Double prod(Object o1, Object o2) {
    if (o1 == null || o2 == null)
        return Double.valueOf("0");
    return Double.valueOf(o1.toString()) * Double.valueOf(o2.toString());
}

From source file:Main.java

/**
 * Rounds the given results to two decimal places.
 * /*from   w  ww  . j  ava2s  .  c o  m*/
 * @param results
 */
private static void roundResults(double[] results) {
    for (int i = 0; i < results.length; i++) {
        double result = results[i];
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        results[i] = Double.valueOf(twoDForm.format(result));
    }
}

From source file:Main.java

public static double getDoubleAttribute(Element node, String attr) {
    double retValue = 0;
    try {/*from w  w  w.java 2 s  .  co  m*/
        String s = node.getAttribute(attr);
        s = s.replace(',', '.');
        //retValue = Double.parseDouble( s );
        retValue = Double.valueOf(s).doubleValue();
    } catch (NumberFormatException ex) {
        System.err.println("Parse error:" + ex.getMessage() + " while reading attr: " + attr);
        lastState = ERROR;
    }
    return retValue;
}

From source file:Main.java

public static double roundTwoDecimals(double d) {
    // try {//from w  w  w.j av  a  2s. com
    //DecimalFormat twoDForm = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.getDefault()));
    // NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
    DecimalFormat dFormat = new DecimalFormat("####,###,###.#");

    return Double.valueOf(dFormat.format(d));
    /**}
    catch (Exception exx)
    {
    return  d;
    }**/
}

From source file:Main.java

/**
 * Convert a number of kilometers to miles.
 * @param km number of km to convert/*  ww w. ja v a 2s . com*/
 * @return number of km in miles
 */
public static double asMiles(final double km) {
    DecimalFormat twoDForm = new DecimalFormat("#.##");
    return Double.valueOf(twoDForm.format(km * MILES_CONVERT));
}

From source file:Main.java

/**
 * Returns the double value of the named attribute for the given node
 * If no such attribute exists, returns 0.0
 *//*  ww w  . j a v a 2s  . co  m*/
public static double getDblValue(Node node, String name) {
    // Look for the attribute
    Node att = get_named_attribute(node, name);
    if (att != null) {
        // Return the value
        return Double.valueOf(att.getNodeValue()).doubleValue();
    } else {
        // No such attribute
        return 0.0;
    }
}

From source file:Main.java

public static Long stringToLong(String str) {
    if (str == null) {
        return null;
    } else {/*from w w  w  .  j ava2 s .  co m*/
        try {
            return Long.parseLong(str);
        } catch (NumberFormatException e) {
            try {
                Double d = Double.valueOf(str);
                if (d.doubleValue() > mMaxLong.doubleValue() + 1.0) {
                    Log.w(TAG, "Value " + d + " too large for long");
                    return null;
                }
                return Long.valueOf(d.longValue());
            } catch (NumberFormatException nfe2) {
                Log.w(TAG,
                        "Unable to interpret value " + str + " in field being "
                                + "converted to long, caught NumberFormatException <" + nfe2.getMessage()
                                + "> field discarded");
                return null;
            }
        }
    }
}

From source file:Main.java

public static Integer stringToInteger(String str) {
    if (str == null) {
        return null;
    } else {/*from   w  w  w  .j  a  v  a  2  s.co  m*/
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException e) {
            try {
                Double d = Double.valueOf(str);
                if (d.doubleValue() > mMaxInt.doubleValue() + 1.0) {
                    Log.w(TAG, "Value " + d + " too large for integer");
                    return null;
                }
                return Integer.valueOf(d.intValue());
            } catch (NumberFormatException nfe2) {
                Log.w(TAG,
                        "Unable to interpret value " + str + " in field being "
                                + "converted to int, caught NumberFormatException <" + e.getMessage()
                                + "> field discarded");
                return null;
            }
        }
    }
}

From source file:Main.java

/**
 * Gets a double value of the given attribute
 * @param node//from   ww w  .j a v a2  s .  c o m
 * @param attrName
 * @param defaultValue
 * @return
 */
public static double getDoubleValue(Node node, String attrName, double defaultValue) {
    String value = getValue(node, attrName, null);

    if (value == null)
        return defaultValue;

    try {
        return Double.valueOf(value);
    } catch (NumberFormatException e) {
        return defaultValue;
    }
}