I thought I could accomplish this easily with something such as the following:
double numInput;
numInput = Double.parseDouble(inputTxtField.getText());
if ((numInput * 100) % 1 != 0) {
// do something
}
However, I'm getting all sorts of strange test cases where such as:
false: 2.11, 2.5, 2.6
true: 2.22, 2.3, 2.2
I just started programming so maybe this is a silly goof, but I thought multiplying a double by 100 and then checking for a remainder when dividing by 1 would work. The intent is to prevent someone from entering a number with more than two decimals. Less than or equal to 2 decimals is fine.
Any tips are appreciated! Thank you!
EDIT: Thank you for all the quick comments! This solved my problem, and I really appreciate the extra information as to why it won't work. Thank you!