I need to check if the number has decimals. Since you can't do type checking for type float or a double I came up with the the following code.
$('#storePaymentForm').submit(function() {
var numberValue = document.getElementById("price").value;
if (numberValue % 1 != 0) {
return true;
}
else {
alert('U moet een bedrag invullen met twee nullen achter de commas!');
return false;
}
});
This code works fine when you enter a number like: 10.23
But when you enter 10.00
it returns false and shows the alert. I've tried several things, but I can't figure it out. Can anyone help me or point me in the right direction how I can check if the number has decimals. And make sure when a user enters 10.00
it returns true instead of false(which is the case right now). The input field is of type number.
The input field looks like this:
<input type="number" id="price" required name="price" min="0" value="0.00" step=".01">