i thought i solved the problem yesterday but it turns out some numbers are not working. i'm not understanding why either because if you go step by step through the code, it should work... anyway, i need every hundredth between 1-4 to round up to 5, and any hundredth between 6-9 to round up to 0 and increment the tenth. so 14.21 goes to 14.25 and 14.26 goes to 14.30, while 14.20 and 14.25 stay the same. code below works for most numbers, but i found that certain ones like 4.02/4.06/5.02/5.06 don't work. why? function Money($adjustedPrice) { $newPrice = $adjustedPrice*100; while($newPrice % 5 != 0) { $newPrice++; } return $newPrice/100; } $adjustedPrice = 5.02; $finalPrice = Money($adjustedPrice); echo number_format($finalPrice, 2); PHP:
This one had me stumped. Not exactly sure why this happens but this will work. function Money($adjustedPrice) { $newPrice =number_format($adjustedPrice*100,0); while($newPrice % 5 != 0) { $newPrice++; } return $newPrice/100; } $adjustedPrice = 5.02; $finalPrice = Money($adjustedPrice); echo number_format($finalPrice, 2); PHP: If anyone knows why this occurs, I would love to know why php behaves this way. My guess is that php does not interpret a (float)*100 as an integer, which is causing the modulus operator to behave in a way that is not expected.