java.lang.Double类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(202)

本文整理了Java中java.lang.Double类的一些代码示例,展示了Double类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Double类的具体详情如下:
包路径:java.lang.Double
类名称:Double

Double介绍

[英]The wrapper for the primitive type double.
[中]基本类型double的包装器。

代码示例

代码示例来源:origin: stackoverflow.com

public static boolean isNumeric(String str)  
{  
 try  
 {  
  double d = Double.parseDouble(str);  
 }  
 catch(NumberFormatException nfe)  
 {  
  return false;  
 }  
 return true;  
}

代码示例来源:origin: google/guava

@Override
protected Double doForward(String value) {
 return Double.valueOf(value);
}

代码示例来源:origin: google/guava

@Override
protected String doBackward(Double value) {
 return value.toString();
}

代码示例来源:origin: skylot/jadx

private static String doubleToString(double value) {
  if (Double.compare(value, Math.floor(value)) == 0
      && !Double.isInfinite(value)) {
    return Integer.toString((int) value);
  }
  // remove trailing zeroes
  NumberFormat f = NumberFormat.getInstance(Locale.ROOT);
  f.setMaximumFractionDigits(4);
  f.setMinimumIntegerDigits(1);
  return f.format(value);
}

代码示例来源:origin: commons-io/commons-io

/**
 * Converts a "double" value between endian systems.
 * @param value value to convert
 * @return the converted value
 */
public static double swapDouble(final double value) {
  return Double.longBitsToDouble( swapLong( Double.doubleToLongBits( value ) ) );
}

代码示例来源:origin: redisson/redisson

@Override
public void writeTag(Object data, MBOut out) {
  double d = ((Double) data).doubleValue();
  {
    byte[] bytes = Double.toString(d).getBytes();
    out.writeArray(bytes, 0, bytes.length);
  }
}

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return new Double(((Number) jv).doubleValue());
    }
    return (Double) null;
  }
};

代码示例来源:origin: apache/incubator-dubbo

public static double unboxed(Double v) {
  return v == null ? 0 : v.doubleValue();
}

代码示例来源:origin: google/guava

/** Returns whether any of the values in {@code dataset} are {@code NaN}. */
private static boolean containsNaN(double... dataset) {
 for (double value : dataset) {
  if (Double.isNaN(value)) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: google/guava

private static boolean areEqual(double a, double b) {
 return Double.doubleToLongBits(a) == Double.doubleToLongBits(b);
}

代码示例来源:origin: google/guava

public void testCompare() {
 for (double x : VALUES) {
  for (double y : VALUES) {
   // note: spec requires only that the sign is the same
   assertEquals(x + ", " + y, Double.valueOf(x).compareTo(y), Doubles.compare(x, y));
  }
 }
}

代码示例来源:origin: google/guava

public void testIsFinite() {
 for (double value : NUMBERS) {
  assertEquals(!(Double.isNaN(value) || Double.isInfinite(value)), Doubles.isFinite(value));
 }
}

代码示例来源:origin: google/guava

/**
 * Compares the two specified {@code double} values. The sign of the value returned is the same as
 * that of <code>((Double) a).{@linkplain Double#compareTo compareTo}(b)</code>. As with that
 * method, {@code NaN} is treated as greater than all other values, and {@code 0.0 > -0.0}.
 *
 * <p><b>Note:</b> this method simply delegates to the JDK method {@link Double#compare}. It is
 * provided for consistency with the other primitive types, whose compare methods were not added
 * to the JDK until JDK 7.
 *
 * @param a the first {@code double} to compare
 * @param b the second {@code double} to compare
 * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is
 *     greater than {@code b}; or zero if they are equal
 */
public static int compare(double a, double b) {
 return Double.compare(a, b);
}

代码示例来源:origin: spring-projects/spring-framework

public boolean valid(Double ratio) {
    return new Double(42).equals(ratio);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@Deprecated
public void hashCodeWithDouble() {
  double dbl = 9830.43;
  int expected = (new Double(dbl)).hashCode();
  assertEquals(expected, ObjectUtils.hashCode(dbl));
}

代码示例来源:origin: apache/incubator-dubbo

@Override
  public Object decode(Object jv) {
    if (jv instanceof Number) {
      return new Double(((Number) jv).doubleValue());
    }
    return (Double) null;
  }
};

代码示例来源:origin: apache/incubator-dubbo

public static double unboxed(Double v) {
  return v == null ? 0 : v.doubleValue();
}

代码示例来源:origin: stackoverflow.com

// 1. static method
if (Double.isNaN(doubleValue)) {
  ...
}
// 2. object's method
if (doubleObject.isNan()) {
  ...
}

代码示例来源:origin: libgdx/libgdx

public static long doubleToLongBits (double value) {
  return Double.doubleToLongBits(value);
}

代码示例来源:origin: google/guava

@GwtIncompatible // DoubleMath.isPowerOfTwo, DoubleMath.log2(double, RoundingMode), StrictMath
public void testIsPowerOfTwo() {
 for (double x : ALL_DOUBLE_CANDIDATES) {
  boolean expected =
    x > 0
      && !Double.isInfinite(x)
      && !Double.isNaN(x)
      && StrictMath.pow(2.0, DoubleMath.log2(x, FLOOR)) == x;
  assertEquals(expected, DoubleMath.isPowerOfTwo(x));
 }
}

相关文章