List of usage examples for java.lang Double valueOf
@HotSpotIntrinsicCandidate public static Double valueOf(double d)
From source file:Main.java
public static Double Doubleformat(DecimalFormat df, Double value) { if (value == null || value.compareTo(0.0) == 0) { return 0.0; }/* w w w. ja v a 2 s. c om*/ if (df == null) { df = doubleFormat; } String dfValue = df.format(value); dfValue = dfValue.replaceAll("[ ]", ""); dfValue = dfValue.replaceAll("[,]", ""); return Double.valueOf(dfValue); }
From source file:Main.java
public static String getTimeZoneOffset() { TimeZone timezone = TimeZone.getDefault(); int i = timezone.getRawOffset() / 1000; int j;/* w ww .j a v a 2 s . com*/ double d; Object aobj[]; if (timezone.useDaylightTime() && timezone.inDaylightTime(new java.sql.Date(System.currentTimeMillis()))) j = 1; else j = 0; d = (double) i / 3600D + (double) j; aobj = new Object[1]; aobj[0] = Double.valueOf(d); return String.format("%.2f", aobj); }
From source file:Main.java
/** * Helper method used to get default value for wrappers used for primitive types * (0 for Integer etc)// w w w . jav a2 s . c o m */ public static Object defaultValue(Class<?> cls) { if (cls == Integer.TYPE) { return Integer.valueOf(0); } if (cls == Long.TYPE) { return Long.valueOf(0L); } if (cls == Boolean.TYPE) { return Boolean.FALSE; } if (cls == Double.TYPE) { return Double.valueOf(0.0); } if (cls == Float.TYPE) { return Float.valueOf(0.0f); } if (cls == Byte.TYPE) { return Byte.valueOf((byte) 0); } if (cls == Short.TYPE) { return Short.valueOf((short) 0); } if (cls == Character.TYPE) { return '\0'; } throw new IllegalArgumentException("Class " + cls.getName() + " is not a primitive type"); }
From source file:Main.java
public static double DoubleLonLatFromString(String string) { int pos = -1; double k = 1f / 60f; double result = 0; if (string.indexOf('.') != -1) { pos = string.indexOf('.'); }/* w ww . j av a 2 s .c o m*/ if (string.indexOf(',') != -1) { pos = string.indexOf(','); } if (pos == -1) { //TODO if (string.length() >= 2) { result = result + Double.valueOf(string.substring(0, 2)); } if (string.length() >= 4) { result = result + k * Double.valueOf(string.substring(2, 4)); } if (string.length() >= 6) { result = result + k * k * Double.valueOf(string.substring(4, string.length())); } } //dd,dddddddddd //ddd.ddddddddd if (pos == 1 || pos == 2) { result = Double.valueOf(string); } //ddmm.mmmmmm //dddmm.mmmmmmmm if (pos == 5) { result = Double.valueOf(string.substring(0, 3)) + k * Double.valueOf(string.substring(3, string.length() - 1)); } //dddmm.mmmmmmmm if (pos == 4) { result = Double.valueOf(string.substring(0, 2)) + k * Double.valueOf(string.substring(2, string.length())); } //ddmmss.ssssssssss if (pos == 6) { result = Double.valueOf(string.substring(0, 2)) + k * Double.valueOf(string.substring(2, 4)) + k * k * Double.valueOf(string.substring(4, string.length())); } //dddmmss.ssssssssss if (pos == 7) { result = Double.valueOf(string.substring(0, 3)) + k * Double.valueOf(string.substring(3, 5)) + k * k * Double.valueOf(string.substring(5, string.length())); } return result; }
From source file:Main.java
/** * Convert a number of meters to feet./*from w w w . j a v a 2 s .c o m*/ * @param meters Value to convert in meters. * @return meters converted to feet. */ public static double asFeet(final double meters) { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(meters * FEET_CONVERT)); }
From source file:Main.java
public static double calculateMinWeight(double height) { DecimalFormat format = new DecimalFormat("0.0"); double result = 18.5 * height * height / 10000; return Double.valueOf(format.format(result).toString()); }
From source file:Main.java
public static double calculateMaxWeight(double height) { DecimalFormat format = new DecimalFormat("0.0"); double result = 24.0 * height * height / 10000; return Double.valueOf(format.format(result).toString()); }
From source file:Main.java
public static double asMiles(final long meters) { DecimalFormat twoDForm = new DecimalFormat("#.##"); return Double.valueOf(twoDForm.format(asMiles(meters / 1000.0))); }
From source file:Main.java
public static double calculateBMI(double weight, double height) { DecimalFormat format = new DecimalFormat("0.00"); double result = weight / (height * height) * 10000; return Double.valueOf(format.format(result).toString()); }
From source file:Main.java
/** * <p>Extract decimal values from an array of strings into an array of double.</p> * * <p>Exceptions in the format of the string are trapped and 0 value(s) returned.</p> * * @param src an array of strings, each of which should be a decimal numeric value * @return an array of double/*w ww .j a v a 2 s. c o m*/ */ static public double[] copyStringToDoubleArray(String[] src) { if (src == null) return null; int n = src.length; double[] dst = new double[n]; for (int j = 0; j < n; ++j) { double value = 0; try { value = Double.valueOf(src[j]).doubleValue(); } catch (NumberFormatException e) { } catch (NullPointerException e) { } dst[j] = value; } return dst; }