Example usage for java.lang Double doubleValue

List of usage examples for java.lang Double doubleValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public double doubleValue() 

Source Link

Document

Returns the double value of this Double object.

Usage

From source file:Main.java

/**
 * Return the real number represented by the String s,
 * or return Double.NaN if s does not represent a legal
 * real number.//from   w  w  w .  j  a v a2s.  c  o  m
 */
public static double stringToReal(String s) {
    try {
        Double d = new Double(s);
        return d.doubleValue();
    } catch (NumberFormatException e) {
        return Double.NaN;
    }
}

From source file:Main.java

public static Integer stringToInteger(String str) {
    if (str == null) {
        return null;
    } else {/*  w  w  w. ja v  a  2  s .  c o  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

/**
 * unbox Double/*from  w ww. j av a2 s.  com*/
 */
public static double unboxed(Double v) {
    return v == null ? 0 : v.doubleValue();
}

From source file:Main.java

public static Long stringToLong(String str) {
    if (str == null) {
        return null;
    } else {//from   w  w w .jav a 2  s  .  c o 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:org.openmrs.util.Format.java

public static String format(Double d) {
    return d == null ? "" : format(d.doubleValue());
}

From source file:org.jpmml.evaluator.RegressionAggregator.java

static double sum(List<Double> values) {
    double result = 0d;

    for (Double value : values) {
        result += value.doubleValue();
    }/*from   w ww  .j  a  v  a2 s .c  o m*/

    return result;
}

From source file:Main.java

public static Double finalScore(Double finalScore, int questionsAnswered, double timeLeft) {
    double multiplier = questionsAnswered + (timeLeft / (timeLeft * 10));
    finalScore = finalScore.doubleValue() * 20 * multiplier;
    finalScore = finalScore * 10;// w  w  w . jav  a  2  s.co m
    return finalScore;

}

From source file:HtmlDimensions.java

public static String formatPct(Double value) {
    String v = "";
    synchronized (pctFormat) {
        v = pctFormat.format(value.doubleValue());
    }//w  w w.  j  a  v  a2s.  co m
    return v;
}

From source file:org.jpmml.evaluator.functions.MeanFunction.java

static private Double evaluate(Collection<?> values) {
    Mean mean = new Mean();

    for (Object value : values) {
        Double doubleValue = (Double) TypeUtil.parseOrCast(DataType.DOUBLE, value);

        mean.increment(doubleValue.doubleValue());
    }/*from   w ww  .  j  a v  a  2 s . c om*/

    return mean.getResult();
}

From source file:Main.java

public static double[] toDoubleArray(List<Double> list, double defaultValue) {
    if (isEmpty(list)) {
        return new double[0];
    }//from   www.  ja va  2 s .  c o  m
    double[] array = new double[list.size()];
    for (int I = 0; I < list.size(); I++) {
        Double v = list.get(I);
        if (v == null) {
            array[I] = defaultValue;
        } else {
            array[I] = v.doubleValue();
        }
    }
    return array;
}