java.lang.Float.parseFloat()方法的使用及代码示例

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

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

Float.parseFloat介绍

[英]Parses the specified string as a float 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

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

public Map<String, ?> get () {
  Map<String, Object> map = new HashMap<String, Object>();
  for (Entry<Object, Object> val : properties.entrySet()) {
    if (val.getValue() instanceof Boolean)
      map.put((String)val.getKey(), (Boolean)Boolean.parseBoolean((String)val.getValue()));
    if (val.getValue() instanceof Integer) map.put((String)val.getKey(), (Integer)Integer.parseInt((String)val.getValue()));
    if (val.getValue() instanceof Long) map.put((String)val.getKey(), (Long)Long.parseLong((String)val.getValue()));
    if (val.getValue() instanceof String) map.put((String)val.getKey(), (String)val.getValue());
    if (val.getValue() instanceof Float) map.put((String)val.getKey(), (Float)Float.parseFloat((String)val.getValue()));
  }
  return map;
}

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

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

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

public float getFloatAttribute (String name, float defaultValue) {
  String value = getAttribute(name, null);
  if (value == null) return defaultValue;
  return Float.parseFloat(value);
}

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

/** Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.
 * @throws GdxRuntimeException if no attribute or child was not found. */
public float getFloat (String name, float defaultValue) {
  String value = get(name, null);
  if (value == null) return defaultValue;
  return Float.parseFloat(value);
}

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

/** Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.
 * @throws GdxRuntimeException if no attribute or child was not found. */
public float getFloat (String name, float defaultValue) {
  String value = get(name, null);
  if (value == null) return defaultValue;
  return Float.parseFloat(value);
}

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

@Override
public Map<String, ?> get () {
  Map<String, Object> map = new HashMap<String, Object>();
  for (Entry<Object, Object> val : properties.entrySet()) {
    if (val.getValue() instanceof Boolean)
      map.put((String)val.getKey(), (Boolean)Boolean.parseBoolean((String)val.getValue()));
    if (val.getValue() instanceof Integer) map.put((String)val.getKey(), (Integer)Integer.parseInt((String)val.getValue()));
    if (val.getValue() instanceof Long) map.put((String)val.getKey(), (Long)Long.parseLong((String)val.getValue()));
    if (val.getValue() instanceof String) map.put((String)val.getKey(), (String)val.getValue());
    if (val.getValue() instanceof Float) map.put((String)val.getKey(), (Float)Float.parseFloat((String)val.getValue()));
  }
  return map;
}

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

public float getFloatAttribute (String name, float defaultValue) {
  String value = getAttribute(name, null);
  if (value == null) return defaultValue;
  return Float.parseFloat(value);
}

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

public float parseFloat(int start, int end) {
  return Float.parseFloat(toString(start, end));
}

代码示例来源:origin: alibaba/fastjson

public float floatValue() {
  String strVal = numberString();
  float floatValue = Float.parseFloat(strVal);
  if (floatValue == 0 || floatValue == Float.POSITIVE_INFINITY) {
    char c0 = strVal.charAt(0);
    if (c0 > '0' && c0 <= '9') {
      throw new JSONException("float overflow : " + strVal);
    }
  }
  return floatValue;
}

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

/** Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.
 * @throws GdxRuntimeException if no attribute or child was not found. */
public float getFloat (String name) {
  String value = get(name, null);
  if (value == null) throw new GdxRuntimeException("Element " + this.name + " doesn't have attribute or child: " + name);
  return Float.parseFloat(value);
}

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

/** Returns the attribute value with the specified name, or if no attribute is found, the text of a child with the name.
 * @throws GdxRuntimeException if no attribute or child was not found. */
public float getFloat (String name) {
  String value = get(name, null);
  if (value == null) throw new GdxRuntimeException("Element " + this.name + " doesn't have attribute or child: " + name);
  return Float.parseFloat(value);
}

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

public float getParameter(String key, float defaultValue) {
  Number n = getNumbers().get(key);
  if (n != null) {
    return n.floatValue();
  }
  String value = getParameter(key);
  if (StringUtils.isEmpty(value)) {
    return defaultValue;
  }
  float f = Float.parseFloat(value);
  getNumbers().put(key, f);
  return f;
}

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

public float getParameter(String key, float defaultValue) {
  Number n = getNumbers().get(key);
  if (n != null) {
    return n.floatValue();
  }
  String value = getParameter(key);
  if (StringUtils.isEmpty(value)) {
    return defaultValue;
  }
  float f = Float.parseFloat(value);
  getNumbers().put(key, f);
  return f;
}

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

public float getMethodParameter(String method, String key, float defaultValue) {
  String methodKey = method + "." + key;
  Number n = getNumbers().get(methodKey);
  if (n != null) {
    return n.floatValue();
  }
  String value = getMethodParameter(method, key);
  if (StringUtils.isEmpty(value)) {
    return defaultValue;
  }
  float f = Float.parseFloat(value);
  getNumbers().put(methodKey, f);
  return f;
}

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

public float getMethodParameter(String method, String key, float defaultValue) {
  String methodKey = method + "." + key;
  Number n = getNumbers().get(methodKey);
  if (n != null) {
    return n.floatValue();
  }
  String value = getMethodParameter(method, key);
  if (StringUtils.isEmpty(value)) {
    return defaultValue;
  }
  float f = Float.parseFloat(value);
  getNumbers().put(methodKey, f);
  return f;
}

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

public static Literal getRealLiteral(String numberToken, int startPos, int endPos, boolean isFloat) {
  try {
    if (isFloat) {
      float value = Float.parseFloat(numberToken);
      return new FloatLiteral(numberToken, startPos, endPos, value);
    }
    else {
      double value = Double.parseDouble(numberToken);
      return new RealLiteral(numberToken, startPos, endPos, value);
    }
  }
  catch (NumberFormatException ex) {
    throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_A_REAL, numberToken));
  }
}

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

protected void loadBasicLayerInfo (MapLayer layer, Element element) {
  String name = element.getAttribute("name", null);
  float opacity = Float.parseFloat(element.getAttribute("opacity", "1.0"));
  boolean visible = element.getIntAttribute("visible", 1) == 1;
  float offsetX = element.getFloatAttribute("offsetx", 0);
  float offsetY = element.getFloatAttribute("offsety", 0);
  layer.setName(name);
  layer.setOpacity(opacity);
  layer.setVisible(visible);
  layer.setOffsetX(offsetX);
  layer.setOffsetY(offsetY);
}

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

protected void loadBasicLayerInfo (MapLayer layer, Element element) {
  String name = element.getAttribute("name", null);
  float opacity = Float.parseFloat(element.getAttribute("opacity", "1.0"));
  boolean visible = element.getIntAttribute("visible", 1) == 1;
  float offsetX = element.getFloatAttribute("offsetx", 0);
  float offsetY = element.getFloatAttribute("offsety", 0);
  layer.setName(name);
  layer.setOpacity(opacity);
  layer.setVisible(visible);
  layer.setOffsetX(offsetX);
  layer.setOffsetY(offsetY);
}

相关文章