Author Topic: Problem with a math code  (Read 300 times)

legor

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Problem with a math code
« on: September 05, 2010, 06:31:52 PM »
I have a math code that is giving to me the wrong answer, I check   already the order of my code but I cannot see the problem, there is my   code
 
  $loan = $_POST['t_loan'];
  $rate = $_POST['rate'];
  $monts = $_POST['months'];
  $f_rate = $rate/100;
 
 
  $payment = ($loan * ($f_rate / 12)) * (pow((1 + ($f_rate / 12)), $monts) / ((pow((1 + ($f_rate / 12)), $monts)) + 1));
 
  $payment = round($payment);
  Print "$payment";
 
  there is the equation
 
 
 
  With a Loan of 18000 rate of 4.9(0.049) and 60 months to pay the result should be a 338 monthly payment but I am getting 41
 
  I really appreciate any help
 
 
 

phphelp

  • Administrator
  • Senior Member
  • *****
  • Posts: 777
  • Karma: +3/-0
    • View Profile
    • PHP Help forum
Re: Problem with a math code
« Reply #1 on: September 06, 2010, 01:31:25 AM »
At the end of your line you have + 1, while on picture it says - 1
Are you experienced in PHP programming and willing to share your knowledge?
Join us at php help forum!

legor

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Problem with a math code
« Reply #2 on: September 06, 2010, 02:25:26 AM »
Yea I figure out early and changed but any way still cannot have the correct result, I changed the code again this one is the new one:

$loan = $_POST['t_loan'];
$rate = $_POST['rate'];
$monts = $_POST['months'];
$f_rate = $rate/100;


$payment = $loan * ($f_rate / 12) * (pow((1 + ($f_rate / 12)), $monts) / pow((1 + ($f_rate / 12)), $monts) - 1);

$payment = round($payment);
Print "$payment";


Smokey PHP

  • Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 506
  • Karma: +4/-0
    • View Profile
Re: Problem with a math code
« Reply #3 on: September 08, 2010, 05:33:27 PM »
Hi there,

Try this line:
PHP Code: [Select]

$payment 
$loan * ($f_rate 12) * (pow((+ ($f_rate 12)), $monts) / (pow((+ ($f_rate 12)), $monts) - 1));


in place of:
PHP Code: [Select]

$payment 
$loan * ($f_rate 12) * (pow((+ ($f_rate 12)), $monts) / pow((+ ($f_rate 12)), $monts) - 1);


Let me know how it goes.

legor

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Problem with a math code
« Reply #4 on: September 09, 2010, 06:25:45 PM »
Thank you very much, now is working.

A++++