Java 源码 - Float

介绍

The Float class wraps a value of primitive type float in an object.

示例

public class Test {
  public static void main(String[] args) {
    Float f = Float.valueOf("0.123F");
    System.out.println(f);
  }
}

源码

public final class Float extends Number implements Comparable<Float> {

  public static final float POSITIVE_INFINITY = 1.0f / 0.0f;

  public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;

  public static Float valueOf(String s) throws NumberFormatException {
    return new Float(parseFloat(s));
  }

  public static Float valueOf(float f) {
    return new Float(f);
  }

  public static float parseFloat(String s) throws NumberFormatException {
    return FloatingDecimal.parseFloat(s);
  }

  public static boolean isNaN(float v) {
    return (v != v);
  }

  public static boolean isInfinite(float v) {
    return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
  }

   public static boolean isFinite(float f) {
    return Math.abs(f) <= FloatConsts.MAX_VALUE;
  }

  private final float value;

  public Float(float value) {
    this.value = value;
  }

  public Float(double value) {
    this.value = (float)value;
  }
}
上一篇:node + node-webkit实现电脑文件信息扫描小插件


下一篇:蓝桥杯python自学笔记