♥bruyndoncx Posted April 12, 2013 Posted April 12, 2013 In my product bundles the savings are calculated. For a particular item it showed a wrong number. I found out it was because of rounding differences there was a difference of -0.00005 echoing the different values during the calculation shows saving: -5.000000000166E-5 i did a rudimentory fix by casting to integer and dividing again like this echo 'saving fix ' . ((int)($bundle_saving*100 ) ) / 100; resulting in the correct result: saving fix 0 the actual display of the savings with the currency notation is generated with this piece of code $bundle_saving = $currencies->display_price($bundle_saving, tep_get_tax_rate($product_info['products_tax_class_id'])); so question is, shouldn't the display_price function be able to handle the exponential notation properly ? or perhaps something wrong with my code ? Can someone try to reproduce this ? I understand i can easily apply this quickfix, but I feel I should fix it for all uses of the currencies->display_price and not just this particular case where I noticed the error. KEEP CALM AND CARRY ON I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support). So if you are still here ? What are you waiting for ?! Find the most frequent unique errors to fix: grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt
MrPhil Posted April 12, 2013 Posted April 12, 2013 Well... that's a common problem when using "floating point" ("real") numbers in a computer. You often end up with numbers that have a little tail on them when multiplying percentages by percentages. Would you be expecting an answer of 0, or of .00005 as the "correct" answer for $bundle_saving? Maybe a call to tep_round() is needed, to round $bundle_saving to something reasonable (say, nearest .01 Euro or whatever) before the display_price() call to add in the tax calculation.
Chris H Posted April 17, 2013 Posted April 17, 2013 Like MrPhil says. It may be worth mentioning that a line such as if ($saving == 0) { can be the source of a puzzling logic error. As for 'tep_round', the osC developers evidently thought it an improvement on php's built-in 'round'. Though I can't see it.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.