I am using one If condition in javascript ,
var iid = "c_poqty_"+itemid;
var calculatedQuantity = document.getElementById(iid).value;
if(! isNaN(actualQuantity)) {
if(actualQuantity >= calculatedQuantity) {
return true;
} else {
alert("You must enter the order qty same or greater than the calculated PO Qty");
document.getElementById(iid).focus();
return false;
}
} else {
alert("Please Enter valid number");
document.getElementById(iid).focus();
return false;
}
Here, calculatedQuantity
is always in float and while actualQuantity
can be integer,
I have one testcase:
calculatedQuantity = 1.0
actualQuantity = 1
Appreciate for your help!
I am using one If condition in javascript ,
var iid = "c_poqty_"+itemid;
var calculatedQuantity = document.getElementById(iid).value;
if(! isNaN(actualQuantity)) {
if(actualQuantity >= calculatedQuantity) {
return true;
} else {
alert("You must enter the order qty same or greater than the calculated PO Qty");
document.getElementById(iid).focus();
return false;
}
} else {
alert("Please Enter valid number");
document.getElementById(iid).focus();
return false;
}
Here, calculatedQuantity
is always in float and while actualQuantity
can be integer,
I have one testcase:
calculatedQuantity = 1.0
actualQuantity = 1
Appreciate for your help!
Share Improve this question edited Nov 29, 2012 at 17:03 husayt 15.2k8 gold badges59 silver badges84 bronze badges asked Oct 31, 2012 at 8:55 Affan PathanAffan Pathan 3081 gold badge6 silver badges15 bronze badges1 Answer
Reset to default 3Actually, I suspect they're both strings. Certainly calculatedQty
is, as you've retrieved it from the value
of an input field, and the value
property's value is always a string. Use parseInt
and/or parseFloat
so you're paring numbers rather than strings.
Consider:
console.log("1.0" > "1"); // "true"
console.log(1.0 > 1); // "false"