return $decimals==='max' ? rtrim($num, '0') : $num;
}
+
+/* price/float comparision helper to be used in any suspicious place for zero values?
+usage:
+if (!floatcmp($value1, $value2))
+ compare value is 0
+*/
+
+define('FLOAT_COMP_DELTA', 0.0000001);
+
+function floatcmp($a, $b)
+{
+ return $a - $b > FLOAT_COMP_DELTA ? 1 : $b - $a > FLOAT_COMP_DELTA ? -1 : 0;
+}
+
//
// Current ui mode.
//
$rep->Line($rep->row + 4);
while ($trans = db_fetch($res))
{
- if ($no_zeros && $trans['TotalAmount'] == 0 && $trans['Allocated'] == 0) continue;
+ if ($no_zeros && floatcmp($trans['TotalAmount'], $trans['Allocated']) == 0) continue;
$rep->NewLine(1, 2);
$rep->TextCol(0, 1, $systypes_array[$trans['type']]);
$rep->TextCol(1, 2, $trans['reference']);
$custrec["Overdue1"]-$custrec["Overdue2"],
$custrec["Overdue2"],
$custrec["Balance"]);
- if ($no_zeros && array_sum($str) == 0) continue;
+ if ($no_zeros && floatcmp(array_sum($str), 0) == 0) continue;
$rep->fontSize += 2;
$rep->TextCol(0, 2, $myrow['name']);
$rep->Line($rep->row + 4);
while ($trans=db_fetch($res))
{
- if ($no_zeros && $trans['TotalAmount'] == 0 && $trans['Allocated'] == 0) continue;
+ if ($no_zeros && floatcmp(abs($trans['TotalAmount']), $trans['Allocated']) == 0) continue;
$rep->NewLine(1, 2);
$rep->TextCol(0, 1, $systypes_array[$trans['type']]);
$rep->TextCol(1, 2, $trans['reference']);
$supprec["Overdue2"],
$supprec["Balance"]);
- if ($no_zeros && array_sum($str) == 0) continue;
+ if ($no_zeros && floatcmp(array_sum($str), 0) == 0) continue;
$rep->fontSize += 2;
$rep->TextCol(0, 2, $myrow['name']);
function check_overdue($row)
{
return $row['OverDue'] == 1
- && (abs($row["TotalAmount"]) - $row["Allocated"] != 0);
+ && floatcmp($row["TotalAmount"], $row["Allocated"]) != 0;
}
//------------------------------------------------------------------------------------------------
$sql = get_sql_for_customer_inquiry();