Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mortage calculator in php wrong amount

Tags:

php

i am working on a simple loan calculator, so simple that it's not even working properly.

function calculatePayment($price, $down, $term)
{
    $loan = $price - $down;
    $rate = (4/100) / 12;
    $month = $term * 12;
    $payment = floor(($loan*$rate/1-pow(1+$rate,(-1*$month)))*100)/100;
    return $payment;
}

echo calculatePayment(200000,0,30);

this output: 666.36

that would be great if the monthly loan payement is this (not that is the 666 number but low number hahah), my problem is this be higher.

why am i getting the this?

like image 651
Adam Avatar asked Dec 05 '11 01:12

Adam


People also ask

How do I calculate my mortgage accurately?

These factors include the total amount you're borrowing from a bank, the interest rate for the loan, and the amount of time you have to pay back your mortgage in full. For your mortgage calc, you'll use the following equation: M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1].

How is mortgage calculated in the Philippines?

In the Philippines, the monthly amortization should not exceed 40% of the Gross Monthly Income, and Gross Monthly Income can be calculated by simply dividing the monthly amortization by 40%. Monthly amortization – This is the calculated monthly amortization payments in Philippine Peso or PHP.

How do you calculate actual loan amount?

In theory, calculating your loan payment is simple. You take the total amount you borrowed (known as your principal), and divide it over the number of months over which you agreed to pay back the loan (known as the term).


1 Answers

I just added put (1-pow(1+$rate,(-1*$month))) this because what is happening here is that $loan*$rate will be divided on 1 only then continue

function calculatePayment($price, $down, $term)
{
$loan = $price - $down;
$rate = (4/100) / 12;
$month = $term * 12;
$payment = floor(($loan*$rate/(1-pow(1+$rate,(-1*$month))))*100)/100;
return $payment;
}

echo calculatePayment(200000,0,30);

The answer is 954.83

like image 62
Seder Avatar answered Oct 07 '22 21:10

Seder