编程语言
首页 > 编程语言> > Java 源码 - Float

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;
  }
}

标签:Float,Java,float,INFINITY,源码,static,return,public
来源: https://www.cnblogs.com/feiqiangsheng/p/15933310.html