MCPcopy Create free account
hub / github.com/banq/jdonframework / isFloat

Method isFloat

src/main/java/com/jdon/util/UtilValidate.java:441–466  ·  view source on GitHub ↗

True if string s is an unsigned floating point(real) number. Also returns true for unsigned integers. If you wish to distinguish between integers and floating point numbers, first call isInteger, then call isFloat. Does not accept exponential notation.

(String s)

Source from the content-addressed store, hash-verified

439 * Does not accept exponential notation.
440 */
441 public static boolean isFloat(String s) {
442 if (isEmpty(s)) return defaultEmptyOK;
443
444 boolean seenDecimalPoint = false;
445
446 if (s.startsWith(decimalPointDelimiter)) return false;
447
448 // Search through string's characters one by one
449 // until we find a non-numeric character.
450 // When we do, return false; if we don't, return true.
451 for (int i = 0; i < s.length(); i++) {
452 // Check that current character is number.
453 char c = s.charAt(i);
454
455 if (c == decimalPointDelimiter.charAt(0)) {
456 if (!seenDecimalPoint)
457 seenDecimalPoint = true;
458 else
459 return false;
460 } else {
461 if (!isDigit(c)) return false;
462 }
463 }
464 // All characters are numbers.
465 return true;
466 }
467
468 /** True if string s is a signed or unsigned floating point
469 * (real) number. First character is allowed to be + or -.

Callers

nothing calls this directly

Calls 3

isEmptyMethod · 0.95
isDigitMethod · 0.95
startsWithMethod · 0.80

Tested by

no test coverage detected