Java教程

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;
  }
}
这篇关于Java 源码 - Float的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!