Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate NPER in PHP

Tags:

php

math

I can't figure out how to calculate NPER in php.

I did not find any article in google.

I'm very weak in math becouse of it i'm asking for help.

This is what i did so far :(

public function Nper($interest, $payment, $loan){
       $nperC = Log10($payment/($payment+$loan+$interest))/Log10(1+$interest);
       return $nperC;
}
if(isset($_POST['NperSubmit'])){
        $calc = new CalculatorModel();
        $months = $calc->Nper($_POST['interest'], $_POST['payment'], $_POST['loan']);
        echo round($months,2);
}

Working code (From Tijo John answer)

public function Nper($interest, $payment, $loan){
        $interest = $interest / 1200;
        $nperC = Log10 ($payment/ ($payment- $loan * $interest)) / Log10(1 + $interest);

        return $nperC;
    }
    $calc = new CalculatorModel();
    $months = $calc->Nper($_POST['interest'], $_POST['payment'], $_POST['loan']);
    echo round($months,2);

Thanks :))

like image 516
Lasha Avatar asked Oct 17 '25 18:10

Lasha


1 Answers

I think you should have change the formula as follows

Log10 ($payment/ ($payment- $loan * $interest)) / Log10(1 + $interest)

like image 181
Tijo John Avatar answered Oct 20 '25 10:10

Tijo John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!