本文整理了Java中java.lang.Float.valueOf()
方法的一些代码示例,展示了Float.valueOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Float.valueOf()
方法的具体详情如下:
包路径:java.lang.Float
类名称:Float
方法名:valueOf
[英]Returns a Float instance for the specified float value.
[中]返回指定浮点值的浮点实例。
代码示例来源:origin: google/guava
@Override
protected Float doForward(String value) {
return Float.valueOf(value);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected Float doParse(String parameter) throws NumberFormatException {
return Float.valueOf(parameter);
}
代码示例来源:origin: apache/incubator-dubbo
public static Float boxed(float v) {
return Float.valueOf(v);
}
代码示例来源:origin: apache/incubator-dubbo
public static Float boxed(float v) {
return Float.valueOf(v);
}
代码示例来源:origin: libgdx/libgdx
public Object getObject () {
return Float.valueOf(value);
}
};
代码示例来源:origin: libgdx/libgdx
public Object getObject () {
return Float.valueOf(value);
}
};
代码示例来源:origin: square/retrofit
@Override public Float convert(ResponseBody value) throws IOException {
return Float.valueOf(value.string());
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Append a float field value.
* @param fieldName the name of the field, usually the member variable name
* @param value the field value
* @return this, to support call-chaining
*/
public ToStringCreator append(String fieldName, float value) {
return append(fieldName, Float.valueOf(value));
}
代码示例来源:origin: google/guava
/**
* A reference implementation for {@code tryParse} that just catches the exception from {@link
* Float#valueOf}.
*/
private static Float referenceTryParse(String input) {
if (input.trim().length() < input.length()) {
return null;
}
try {
return Float.valueOf(input);
} catch (NumberFormatException e) {
return null;
}
}
代码示例来源: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: google/guava
@GwtIncompatible // Floats.tryParse
private static void checkTryParse(float expected, String input) {
assertEquals(Float.valueOf(expected), Floats.tryParse(input));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testStringToFloat() {
assertEquals(Float.valueOf("1.0"), conversionService.convert("1.0", Float.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testFloatToString() {
assertEquals("1.0", conversionService.convert(Float.valueOf("1.0"), String.class));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Test update with dynamic SQL.
*/
@Test
public void testSqlUpdateWithArguments() throws Exception {
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ? and PR = ?";
int rowsAffected = 33;
given(this.preparedStatement.executeUpdate()).willReturn(rowsAffected);
int actualRowsAffected = this.template.update(sql,
4, new SqlParameterValue(Types.NUMERIC, 2, Float.valueOf(1.4142f)));
assertTrue("Actual rows affected is correct", actualRowsAffected == rowsAffected);
verify(this.preparedStatement).setObject(1, 4);
verify(this.preparedStatement).setObject(2, Float.valueOf(1.4142f), Types.NUMERIC, 2);
verify(this.preparedStatement).close();
verify(this.connection).close();
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testLang1087(){
// no sign cases
assertEquals(Float.class, NumberUtils.createNumber("0.0").getClass());
assertEquals(Float.valueOf("0.0"), NumberUtils.createNumber("0.0"));
// explicit positive sign cases
assertEquals(Float.class, NumberUtils.createNumber("+0.0").getClass());
assertEquals(Float.valueOf("+0.0"), NumberUtils.createNumber("+0.0"));
// negative sign cases
assertEquals(Float.class, NumberUtils.createNumber("-0.0").getClass());
assertEquals(Float.valueOf("-0.0"), NumberUtils.createNumber("-0.0"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void parseNumberUsingNumberFormat() {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
String aByte = "" + Byte.MAX_VALUE;
String aShort = "" + Short.MAX_VALUE;
String anInteger = "" + Integer.MAX_VALUE;
String aLong = "" + Long.MAX_VALUE;
String aFloat = "" + Float.MAX_VALUE;
String aDouble = "" + Double.MAX_VALUE;
assertEquals("Byte did not parse", Byte.valueOf(Byte.MAX_VALUE), NumberUtils.parseNumber(aByte, Byte.class, nf));
assertEquals("Short did not parse", Short.valueOf(Short.MAX_VALUE), NumberUtils.parseNumber(aShort, Short.class, nf));
assertEquals("Integer did not parse", Integer.valueOf(Integer.MAX_VALUE), NumberUtils.parseNumber(anInteger, Integer.class, nf));
assertEquals("Long did not parse", Long.valueOf(Long.MAX_VALUE), NumberUtils.parseNumber(aLong, Long.class, nf));
assertEquals("Float did not parse", Float.valueOf(Float.MAX_VALUE), NumberUtils.parseNumber(aFloat, Float.class, nf));
assertEquals("Double did not parse", Double.valueOf(Double.MAX_VALUE), NumberUtils.parseNumber(aDouble, Double.class, nf));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void parseNumberRequiringTrimUsingNumberFormat() {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
String aByte = " " + Byte.MAX_VALUE + " ";
String aShort = " " + Short.MAX_VALUE + " ";
String anInteger = " " + Integer.MAX_VALUE + " ";
String aLong = " " + Long.MAX_VALUE + " ";
String aFloat = " " + Float.MAX_VALUE + " ";
String aDouble = " " + Double.MAX_VALUE + " ";
assertEquals("Byte did not parse", Byte.valueOf(Byte.MAX_VALUE), NumberUtils.parseNumber(aByte, Byte.class, nf));
assertEquals("Short did not parse", Short.valueOf(Short.MAX_VALUE), NumberUtils.parseNumber(aShort, Short.class, nf));
assertEquals("Integer did not parse", Integer.valueOf(Integer.MAX_VALUE), NumberUtils.parseNumber(anInteger, Integer.class, nf));
assertEquals("Long did not parse", Long.valueOf(Long.MAX_VALUE), NumberUtils.parseNumber(aLong, Long.class, nf));
assertEquals("Float did not parse", Float.valueOf(Float.MAX_VALUE), NumberUtils.parseNumber(aFloat, Float.class, nf));
assertEquals("Double did not parse", Double.valueOf(Double.MAX_VALUE), NumberUtils.parseNumber(aDouble, Double.class, nf));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void parseNumberRequiringTrim() {
String aByte = " " + Byte.MAX_VALUE + " ";
String aShort = " " + Short.MAX_VALUE + " ";
String anInteger = " " + Integer.MAX_VALUE + " ";
String aLong = " " + Long.MAX_VALUE + " ";
String aFloat = " " + Float.MAX_VALUE + " ";
String aDouble = " " + Double.MAX_VALUE + " ";
assertEquals("Byte did not parse", Byte.valueOf(Byte.MAX_VALUE), NumberUtils.parseNumber(aByte, Byte.class));
assertEquals("Short did not parse", Short.valueOf(Short.MAX_VALUE), NumberUtils.parseNumber(aShort, Short.class));
assertEquals("Integer did not parse", Integer.valueOf(Integer.MAX_VALUE), NumberUtils.parseNumber(anInteger, Integer.class));
assertEquals("Long did not parse", Long.valueOf(Long.MAX_VALUE), NumberUtils.parseNumber(aLong, Long.class));
assertEquals("Float did not parse", Float.valueOf(Float.MAX_VALUE), NumberUtils.parseNumber(aFloat, Float.class));
assertEquals("Double did not parse", Double.valueOf(Double.MAX_VALUE), NumberUtils.parseNumber(aDouble, Double.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void parseNumber() {
String aByte = "" + Byte.MAX_VALUE;
String aShort = "" + Short.MAX_VALUE;
String anInteger = "" + Integer.MAX_VALUE;
String aLong = "" + Long.MAX_VALUE;
String aFloat = "" + Float.MAX_VALUE;
String aDouble = "" + Double.MAX_VALUE;
assertEquals("Byte did not parse", Byte.valueOf(Byte.MAX_VALUE), NumberUtils.parseNumber(aByte, Byte.class));
assertEquals("Short did not parse", Short.valueOf(Short.MAX_VALUE), NumberUtils.parseNumber(aShort, Short.class));
assertEquals("Integer did not parse", Integer.valueOf(Integer.MAX_VALUE), NumberUtils.parseNumber(anInteger, Integer.class));
assertEquals("Long did not parse", Long.valueOf(Long.MAX_VALUE), NumberUtils.parseNumber(aLong, Long.class));
assertEquals("Float did not parse", Float.valueOf(Float.MAX_VALUE), NumberUtils.parseNumber(aFloat, Float.class));
assertEquals("Double did not parse", Double.valueOf(Double.MAX_VALUE), NumberUtils.parseNumber(aDouble, Double.class));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testCreateFloat() {
assertEquals("createFloat(String) failed", Float.valueOf("1234.5"), NumberUtils.createFloat("1234.5"));
assertEquals("createFloat(null) failed", null, NumberUtils.createFloat(null));
this.testCreateFloatFailure("");
this.testCreateFloatFailure(" ");
this.testCreateFloatFailure("\b\t\n\f\r");
// Funky whitespaces
this.testCreateFloatFailure("\u00A0\uFEFF\u000B\u000C\u001C\u001D\u001E\u001F");
}
内容来源于网络,如有侵权,请联系作者删除!