本文整理汇总了Java中sun.misc.FloatingDecimal.parseFloat方法的典型用法代码示例。如果您正苦于以下问题:Java FloatingDecimal.parseFloat方法的具体用法?Java FloatingDecimal.parseFloat怎么用?Java FloatingDecimal.parseFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.misc.FloatingDecimal
的用法示例。
在下文中一共展示了FloatingDecimal.parseFloat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParseFloat
import sun.misc.FloatingDecimal; //导入方法依赖的package包/类
private static int testParseFloat() {
System.out.println(" testParseFloat");
int failures = 0;
for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
float[] f = new float[] {
RANDOM.nextInt(),
(float)RANDOM.nextGaussian(),
RANDOM.nextFloat()*Float.MAX_VALUE
};
for(int j = 0; j < f.length; j++) {
OldFloatingDecimalForTest ofd = new OldFloatingDecimalForTest(f[j]);
String javaFormatString = ofd.toJavaFormatString();
ofd = OldFloatingDecimalForTest.readJavaFormatString(javaFormatString);
float oldFloat = ofd.floatValue();
float newFloat = FloatingDecimal.parseFloat(javaFormatString);
failures += check("testParseFloat", oldFloat, newFloat);
}
}
return failures;
}
示例2: parseFloat
import sun.misc.FloatingDecimal; //导入方法依赖的package包/类
/**
* Returns a new {@code float} initialized to the value
* represented by the specified {@code String}, as performed
* by the {@code valueOf} method of class {@code Float}.
*
* @param s the string to be parsed.
* @return the {@code float} value represented by the string
* argument.
* @throws NullPointerException if the string is null
* @throws NumberFormatException if the string does not contain a
* parsable {@code float}.
* @see java.lang.Float#valueOf(String)
* @since 1.2
*/
public static float parseFloat(String s) throws NumberFormatException {
return FloatingDecimal.parseFloat(s);
}