AnsweredAssumed Answered

PHP Ceil Rounding Error

Question asked by on Aug 6, 2015
Latest reply on Aug 7, 2015 by
This has been driving me crazy!  The ceil function seems to be rounding up whole numbers.  For example,

$bean->monthly_interest_payment_c = ceil($bean->loan_amt_c * ($bean->interest_rate_c / 100) / 12 * 100) / 100;
When I plug in $450,000 for Loan Amt and 14 for Interest Rate, it should come out to an even $5,250.00, but it is adding an extra cent to $5,250.01 ?!?!

To test it, I added a test variable that exactly the same as the above Monthly Interest Payment but without the ceil function.  Then I did a simple boolean test to see if they were equal, and they were not!

The Monthly Interest Payment and the Loan Amt are currency fields, and the Interest Rate is a decimal field.

The REALLY weird thing is when I plug in $100,000 for Loan Amt and 12 for Interest Rate, it calculates the Monthly Payment CORRECTLY at $1000.00.

Please help!  This is driving me nuts!