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 String sGetDecimalStringAnyLocaleAs1Pt5LocalisedString(String value) {

    Locale theLocale = Locale.getDefault();

    NumberFormat numberFormat = DecimalFormat.getInstance(theLocale);
    Number theNumber;//  w ww. jav  a 2s .c  o  m
    try {
        theNumber = numberFormat.parse(value);
    } catch (ParseException e) {

        //value = sConvertDigits(value);
        String valueWithDot = value.replaceAll(",", ".");

        theNumber = Double.valueOf(valueWithDot);
    }

    // String.format uses the JVM's default locale.
    //String s = String.format(Locale.US, "%.2f", price);
    NumberFormat outputFormat = DecimalFormat.getInstance(theLocale);
    outputFormat.setMinimumIntegerDigits(1);
    outputFormat.setMinimumFractionDigits(5);
    outputFormat.setMaximumFractionDigits(5);
    String theStringResult = outputFormat.format(theNumber);
    //String theStringResult = String.format("%1.5f", theDoubleValue.doubleValue());

    return theStringResult;
}

From source file:Main.java

public static Double div(Double v1, Double v2, int scale) {
    if (scale < 0) {
        throw new IllegalArgumentException("The scale must be a positive integer or zero");
    }//from  ww w .  ja  va2  s.c o m
    BigDecimal b1 = new BigDecimal(v1.toString());
    BigDecimal b2 = new BigDecimal(v2.toString());
    return Double.valueOf(b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).doubleValue());
}

From source file:Main.java

public static void bindValores(SQLiteStatement statement, ContentValues contentValues) {
    Set<String> chaves = new TreeSet<>(contentValues.keySet());
    int index = 1;

    for (String chave : chaves) {
        Object valor = contentValues.get(chave);

        if (valor == null) {
            statement.bindNull(index);//from  www .  ja va  2  s.  com

        } else if (valor instanceof String) {
            statement.bindString(index, (String) valor);

        } else if (valor instanceof Double || valor instanceof Float) {
            statement.bindDouble(index, Double.valueOf(String.valueOf(valor)));

        } else if (valor instanceof Integer || valor instanceof Long) {
            statement.bindLong(index, Long.valueOf(String.valueOf(valor)));
        } else if (valor instanceof byte[]) {
            statement.bindBlob(index, (byte[]) valor);
        }
        index++;
    }
}

From source file:Main.java

/**
 * @param threadToCpuRatio - for example, assuming you have 2 CPUs and setting a threadToCpuRation to 3, the result will be a pool with 6 working threads.  
 * @return an {@link ExecutorService} with defined amount of worker thread for each CPUm A {@link SynchronousQueue} and a {@link ThreadPoolExecutor.CallerRunsPolicy}
 *///from   w  ww .  j a  v  a  2s.  c  o m
public static ExecutorService getQueuedThreadPool(double threadToCpuRatio, int queueCapacity) {
    int workingThreads = Double.valueOf(NUM_CPU * threadToCpuRatio).intValue();
    return new ThreadPoolExecutor(workingThreads, workingThreads, 60, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(queueCapacity), new ThreadPoolExecutor.CallerRunsPolicy());
}

From source file:Main.java

/**
 * From http://stackoverflow.com/a/19498994/423980
 * @return  distance between 2 points, stored as 2 pair location;
 *///from w w w . ja  v  a 2  s . c  om
public static double distanceFrom(double lat1, double lng1, double lat2, double lng2) {
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = EARTH_RADIOUS * c;
    return Double.valueOf(dist * METER_CONVERSION).floatValue();
}

From source file:Main.java

public static Element createTextElement(Element parent, String tagName, double v) {
    return createTextElement(parent, tagName, Double.valueOf(v).toString());
}

From source file:Main.java

public static Double getDoubleAttr(Element element, String name) {
    String attr = element.getAttribute(name);
    if (!attr.isEmpty()) {
        Double ret = Double.valueOf(attr);
        return ret;
    }//from  ww w.  j  a  va2 s.c o  m
    return null;
}

From source file:Main.java

public static double getRawDouble(String text) {

    double result = 0.;
    try {/*from w w w .j av  a2  s. co m*/
        result = Double.valueOf(text.trim().replace(',', '.'));
    } catch (NumberFormatException e) {
    }
    return result;
}

From source file:Main.java

public static double[] intToDoubleArray(int[] input) {
    int length = input.length;
    double[] output = new double[length];
    for (int i = 0; i < length; i++) {
        output[i] = Double.valueOf(String.valueOf(input[i]));
    }/*from  ww w  .ja  v a 2 s  . co  m*/
    return output;
}

From source file:Main.java

public static int convert2Int(Object value, int defaultValue) {
    if (value == null || "".equals(value.toString().trim())) {
        return defaultValue;
    }//from w w  w .j a va  2 s.c o m
    try {
        return Double.valueOf(value.toString()).intValue();
    } catch (Exception e) {
        e.printStackTrace();
        return defaultValue;
    }
}