|
|
|
| Non-WTF Job: 4 Senior C# Developers Needed Now! (Cincinnati, OH) |
| « 168.168.2.40 Now Boarding | Tech Support Heck » |
Originally posted by Zecc...
Just bumped against this code on my current project:
if($_REQUEST['discount_price'][$key] != 0) //avoid division by 0 { $value = floatval($_REQUEST['list_price'][$key]); $discount = - 100 + ($value * 100) / $value; $discount = round($discount, 2); } else $discount = 100;With discounts like these, I think I'll stick to the list price, thank you.
Hint: $_REQUEST can be used to access GET/POST variables and cookies.
Hint 2: Figure out what "-100 + (x * 100) / x" works out to.
|
How does checking the discount price for zero prevent a divide by zero when dividing by the list price?
|
Whether or not the numbers are rational, the code definitely isn't. |
| « 168.168.2.40 Now Boarding | Tech Support Heck » |