Topic: Invoice not converting from DN due to float bug
While converting the delivery note to the invoice the system is showing the following error:
Selected quantity cannot be less than quantity credited nor more than quantity not invoiced yet.
To re-produce
1 i created an SO and DN of 28 pieces.
2. Invoiced 19.60 pcs
3. and now while invoicing the remaining 8.40 pcs i get the above error.
I have checked the above in FA's latest build as well.
While investigating i found that in the following function in data_checks.inc, the $num>$max is going true. please note that both $num and $max are both 8.4, and $num can not be greater than $max.
But if i subtract $num-$max it gives me 1.7763568394003E-15(which should be zero). I googled it and found out that this is due to the shortcoming of floating point arithmetic.
Reference Function
function check_num($postname, $min=null, $max=null, $dflt=0) {
if(!isset($_POST[$postname]))
return 0;
$num = input_num($postname, $dflt);
if ($num === false || $num === null)
return 0;
if (isset($min) && ($num<$min))
return 0;
if (isset($max) && ($num>$max))
return 0;
return 1;
}
Should i add a rounding value like 0.00001 in $num for comparing it with $min and $max?
Kindly advise.