MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / parseFloat

Method parseFloat

vm/JavaAPI/src/java/lang/StringToReal.java:286–315  ·  view source on GitHub ↗

Returns the closest float value to the real number in the string. @param s the String that will be parsed to a floating point @return the float closest to the real number @exception NumberFormatException if the String doesn't represent a float

(String s)

Source from the content-addressed store, hash-verified

284 * if the String doesn't represent a float
285 */
286 public static float parseFloat(String s) {
287 s = s.trim();
288 int length = s.length();
289
290 if (length == 0) {
291 throw invalidReal(s, false);
292 }
293
294 // See if this could be a named float
295 char last = s.charAt(length - 1);
296 if (last == 'y' || last == 'N') {
297 return parseName(s, false);
298 }
299
300 // See if it could be a hexadecimal representation
301 // We don't use startsWith because there might be a leading sign.
302 /*if (s.indexOf("0x") != -1 || s.indexOf("0X") != -1) {
303 return HexStringParser.parseFloat(s);
304 }*/
305
306 StringExponentPair info = initialParse(s, length, false);
307 if (info.infinity || info.zero) {
308 return info.specialValue();
309 }
310 float result = parseFltImpl(info.s, (int) info.e);
311 if (Float.floatToIntBits(result) == 0xffffffff) {
312 throw invalidReal(s, false);
313 }
314 return info.negative ? -result : result;
315 }
316}

Callers 1

parseFloatMethod · 0.95

Calls 9

invalidRealMethod · 0.95
parseNameMethod · 0.95
initialParseMethod · 0.95
specialValueMethod · 0.95
parseFltImplMethod · 0.95
floatToIntBitsMethod · 0.95
trimMethod · 0.65
lengthMethod · 0.65
charAtMethod · 0.65

Tested by

no test coverage detected