I have an issue with the JavaScript validation.
In the if condition I am checking few textbox values which will be decimal always but the if condition returns true
for the following! (I checked with the numbers in chrome console).
76.02 != 61.02 + 15
However it returns false for the following.
76.02 != 61 + 15.02
When I checked 61.02+15
it returns 76.02000000000001
and 61+15.02 = 76.02
.
Can anyone tell me why?
And how to fix the issues like this?
Code
if (getNumber($(this).find('[id$="txtAllowed"]').val()) !=
(getNumber($(this).find('[id$="txtPayment"]').val())
+ getNumber($(this).find('[id$="txtBal"]').val()))
{
}
function getNumber(val) {
if (val.trim() == "") {
return 0;
} else if (isNaN(val.trim())) {
return 0;
}
return parseFloat(val.trim());
}
Thank You.