- global $thoseps, $decseps;
- $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
- $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
- //return number_format($number, $decimals, $dsep, $tsep);
- $delta = ($number < 0 ? -.0000000001 : .0000000001);
- return number_format($number+$delta, $decimals, $dsep, $tsep);
+ global $SysPrefs;
+ $tsep = $SysPrefs->thoseps[user_tho_sep()];
+ $dsep = $SysPrefs->decseps[user_dec_sep()];
+
+ if ($number == '')
+ $number = 0;
+ if($decimals==='max')
+ $dec = 15 - floor(log10(abs($number)));
+ else {
+ $delta = ($number < 0 ? -.0000000001 : .0000000001);
+ @$number += $delta;
+ $dec = $decimals;
+ }
+
+ $num = number_format($number, $dec, $dsep, $tsep);
+
+ 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.004);
+
+function floatcmp($a, $b)
+{
+ return $a - $b > FLOAT_COMP_DELTA ? 1 : ($b - $a > FLOAT_COMP_DELTA ? -1 : 0);