Why is rfd_total > max_rfd true? I don’t understand how rfd_total can be greater than max_rfd in the following code:
max_rfd = parseFloat(jQuery('#mx-rfd_'+order_id).val()).toFixed(2);
rfd_total = parseFloat(items_total+tax_total+shipping+allowances*1).toFixed(2);
if( rfd_total > max_rfd)
{ if(isNaN(rfd_total)) alert('rfd_total isNaN'); // not triggered
if(isNaN(max_rfd)) alert('max_rfd isNaN'); // not triggered
alert(rfd_total); // alerts 51.16
alert(max_rfd); // alerts 102.32
return false;
}
It’s because
rfd_totalanmax_rfdare Strings.You will notice that
"51.16" > "102.32"returns true.toFixed()returns a string.You will need to coerce your variables to numbers, which you can find out how to do with a quick search.
Or you can keep your code clean and do it properly using a function such as this one