public class IfNumber
{
public static boolean doubleCheck(String numStr)
{
if(numStr.indexOf(".") >= 0) // Since dot is not a valid input from user
return false; // the method return false.
numStr = numStr.replaceAll(",", "."); // Since "," is valid as input and at
try // the conversion at parse double the
{ // machine needs to have a "." we replace
double number = Double.parseDouble(numStr); //"," with "."
return true;
}
catch(NumberFormatException e)
{
return false;
}
}
}
same class could be used to create other static methods to check for integers, bytes, longs and other primitive number types.
hope I helped save people some time that I've could've save if I've come up with it a year earlier ^^
Edited by Roman Y, 07 August 2010 - 12:32 PM.


Sign In
Create Account


Back to top









