Added isNumber for characters

This commit is contained in:
nathan 2017-07-18 16:34:06 +02:00
parent 740087f2cf
commit c8f2bef1d9
1 changed files with 12 additions and 0 deletions

View File

@ -39,6 +39,17 @@ class MathUtil {
return isNumber(string, 19);
}
/**
* Checks to see if the character is a number
*
* @return true if it's a number, false otherwise
*/
public static
boolean isNumber(final char character) {
// way faster than Character.isDigit()
return character >= '0' && character <= '9';
}
/**
* Checks to see if the string is a number
*
@ -72,6 +83,7 @@ class MathUtil {
for (; i < length; i++) {
char c = string.charAt(i);
// way faster than Character.isDigit()
if (c < '0' || c > '9') {
return false;
}