One way to tackle the problem is, you can use regex to first ensure that the input exactly matches the format of a number with fractional part being optional and if at all then all being zeroes and if yes, then go ahead and parse it else throw Exception or whatever you want to do. Check this Java code,
List<String> list = Arrays.asList("1.00000","1","1.0001");
Pattern intPat = Pattern.compile("(\\d+)(\\.0+)?");
list.forEach(x -> {
Matcher m = intPat.matcher(x);
if (m.matches()) {
int num = Integer.parseInt(m.group(1));
System.out.println(num);
} else {
System.out.println(x +" is not a pure Integer"); // Throw exception or whatever you like
}
});
Outputs,
1
1
1.0001 is not an Integer
Also, as long as the numbers you are working with are confined within integer range, its all good but to ensure the numbers don't cross integer limit, you may want to use a different quantifier.
Another alternate simpler solution you can go for is, parse the number as double and compare it with its int form and if both are equal then it is a pure integer else not. I'll prefer this than my first solution using regex. Java code,
List<String> list = Arrays.asList("1.00000","1","1.0001");
list.forEach(x -> {
double num = Double.parseDouble(x);
if (num == (int)num) {
System.out.println((int)num);
} else {
System.out.println(x + " is not a pure Integer");
}
Prints,
1
1
1.0001 is not a pure Integer
1.00000is never anint.