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

x33g5p2x  于2022-01-17 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(214)

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

Float介绍

[英]The Float class wraps a value of primitive type float in an object. An object of type Float contains a single field whose type is float.

In addition, this class provides several methods for converting a float to a String and a String to a float, as well as other constants and methods useful when dealing with a float.
[中]Float类将基本类型Float的值包装在对象中。Float类型的对象包含一个类型为Float的字段。
此外,该类还提供了几个方法,用于将浮点转换为字符串,将字符串转换为浮点,以及处理浮点时有用的其他常量和方法。

代码示例

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

@Override
public float convertToFloat(CharSequence value) {
  if (value instanceof AsciiString) {
    return ((AsciiString) value).parseFloat();
  }
  return Float.parseFloat(value.toString());
}

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

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

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

private Object toObject (String key, String value) {
  if (key.endsWith("b")) return new Boolean(Boolean.parseBoolean(value));
  if (key.endsWith("i")) return new Integer(Integer.parseInt(value));
  if (key.endsWith("l")) return new Long(Long.parseLong(value));
  if (key.endsWith("f")) return new Float(Float.parseFloat(value));
  return value;
}

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

/** True if the vector represents a pair of valid, non-infinite floating point numbers. */
public final boolean isValid() {
 return !Float.isNaN(x) && !Float.isInfinite(x) && !Float.isNaN(y) && !Float.isInfinite(y);
}

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

/**
 * Converts a "float" value between endian systems.
 * @param value value to convert
 * @return the converted value
 */
public static float swapFloat(final float value) {
  return Float.intBitsToFloat( swapInteger( Float.floatToIntBits( value ) ) );
}

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

public static float unboxed(Float v) {
  return v == null ? 0 : v.floatValue();
}

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

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

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

/**
 * to byte array.
 *
 * @param v   value.
 * @param b   byte array.
 * @param off array offset.
 */
public static void float2bytes(float v, byte[] b, int off) {
  int i = Float.floatToIntBits(v);
  b[off + 3] = (byte) i;
  b[off + 2] = (byte) (i >>> 8);
  b[off + 1] = (byte) (i >>> 16);
  b[off + 0] = (byte) (i >>> 24);
}

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

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

代码示例来源:origin: prestodb/presto

@Test
  public void testNanHash()
  {
    int[] nanRepresentations = {floatToIntBits(Float.NaN), 0xffc00000, 0x7fc00000, 0x7fc01234, 0xffc01234};
    for (int nanRepresentation : nanRepresentations) {
      assertTrue(isNaN(intBitsToFloat(nanRepresentation)));
      assertEquals(RealOperators.hashCode(nanRepresentation), RealOperators.hashCode(nanRepresentations[0]));
    }
  }
}

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

public Object addOne(ProceedingJoinPoint pjp, Float value) throws Throwable {
  float fv = value.floatValue();
  return pjp.proceed(new Object[] {new Float(fv + 1.0F)});
}

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

/**
 * to int.
 *
 * @param b   byte array.
 * @param off offset.
 * @return int.
 */
public static float bytes2float(byte[] b, int off) {
  int i = ((b[off + 3] & 0xFF) << 0) +
      ((b[off + 2] & 0xFF) << 8) +
      ((b[off + 1] & 0xFF) << 16) +
      ((b[off + 0]) << 24);
  return Float.intBitsToFloat(i);
}

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

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

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

@Test
public void withUncheckedObjectValue() throws Exception {
  Float value = new Float("99.45");
  this.tag.setPath("myFloat");
  this.tag.setValue(value);
  int result = this.tag.doStartTag();
  assertEquals(Tag.SKIP_BODY, result);
  String output = getOutput();
  assertTagOpened(output);
  assertTagClosed(output);
  assertContainsAttribute(output, "name", "myFloat");
  assertContainsAttribute(output, "type", "radio");
  assertContainsAttribute(output, "value", value.toString());
  assertAttributeNotPresent(output, "checked");
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * Checks whether the float value is the special NaN value.
 *
 * @return true if NaN
 */
public boolean isNaN() {
  return Float.isNaN(value);
}

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

@Test
@Deprecated
public void hashCodeWithFloat() {
  float flt = 34.8f;
  int expected = (new Float(flt)).hashCode();
  assertEquals(expected, ObjectUtils.hashCode(flt));
}

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

public static float unboxed(Float v) {
  return v == null ? 0 : v.floatValue();
}

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

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

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

/**
 * to byte array.
 *
 * @param v   value.
 * @param b   byte array.
 * @param off array offset.
 */
public static void float2bytes(float v, byte[] b, int off) {
  int i = Float.floatToIntBits(v);
  b[off + 3] = (byte) i;
  b[off + 2] = (byte) (i >>> 8);
  b[off + 1] = (byte) (i >>> 16);
  b[off + 0] = (byte) (i >>> 24);
}

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

@Override
  public String toString () {
    String result = "";
    for (int i = 0; i < data.length; i += 3) {
      result += Float.toString(data[i]) + ", " + Float.toString(data[i + 1]) + ", " + Float.toString(data[i + 2]) + "\n";
    }
    return result;
  }
}

相关文章