Jump to content

Recommended Posts

 

how do i code this properly as you can see i use floor becouse of the result of

13.3333333333333 how is it done with the added 33 pence on the end cheers.

 

 

<?php
define("INTREST",00.05);
$price=100;
$result=$price*INTREST;
$year_intrest=$result*12;
$total=$price+$year_intrest;
$total_payment_monthly=$total/12;

echo "Dear cutomer your product cost: $price 
<br>
Your current intrest is: ".INTREST."%
<br>
The total 12 month intrest is: $year_intrest
<br>
The total price is: $total 
<br>
Please pay: ".floor($total_payment_monthly)." monthly";
?>

Link to comment
https://forums.phpfreaks.com/topic/39797-intrest-monthly-plan/
Share on other sites

<?php
define("INTREST",00.05);
$price=100;
$result=$price*INTREST;
$year_intrest=$result*12;
$total=$price+$year_intrest;
$total_payment_monthly=number_format(($total/12),2);

echo "Dear cutomer your product cost: $price 
<br>
Your current intrest is: ".INTREST."%
<br>
The total 12 month intrest is: $year_intrest
<br>
The total price is: $total 
<br>
Please pay: $total_payment_monthly monthly";
?>

 

You do realize that those payment calculations are wrong? You can't simply figure the interest on the priciple for a year and then divide by 12. There was a post here a few days ago from someone looking for a proper formula and I gave a solution - see below:

 

<html>
<head></head>
<body>

<?php

if ($_POST['principle']) {
 $principle = $_POST['principle'];
 $months = $_POST['months'];
 $apr = $_POST['apr'];
 $rate = $apr/12/100;

 echo "Rate (per period): {$rate}<br>";

 $payment = ( $rate + $rate/( pow((1+$rate),$months)-1) ) * $principle;

 echo "Payment: " . $payment;

}



?>

<form action="<? PHP_SELF ?>" method="POST">
Principle: <input type="text" name="principle" value="<?=$principle?>"><br>
Months: <input type="text" name="months" value="<?=$months?>"><br>
Apr: <input type="text" name="apr" value="<?=$apr?>"><br>
<input type="submit" name="submit">

</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/39797-intrest-monthly-plan/#findComment-192189
Share on other sites

total payment monthly needs to be 13.33 not 13.333333333 so i used ceil but that not correct so what do i do cheers.

 

You already have two solutions posted above: number_format() and round()

 

But, as i also stated your calculations are not correct because interest is calculated each period.

Link to comment
https://forums.phpfreaks.com/topic/39797-intrest-monthly-plan/#findComment-192194
Share on other sites

Which code? The code to fix your problem or the correct interest calculation. You are the one needing help, don't make me do all the work.

 

If you are inquiring concerning the interest calculation then there is really nothing to explain. There are four variables involved:

 

$principle: the loan amount

$months: number of months (or periods) to pay off the loan

$apr: Annual percentage rate

 

Then you calculate the period rate, In this case it is apr / 12 months (I also divide by 100 because I assumed the rate would be entered as 5 instead of .05).

 

$rate = $apr/12/100;

 

Then the formula to calculate the payment per period in order to pay off the principle over the lifetime of the loan is this:

 

$payment = ( $rate + $rate/( pow((1+$rate),$months)-1) ) * $principle;

 

There are pleny of sites out there on how to properly calculate numbers related to loans, just do a Google search. To illustrate the issue, let's suppose you have a $100 loan to be paid in two payments over a year and the interest rate is %10. If you assumed that the total interest would be $10, you would be wrong. The interest is caluculated each period.

 

So at the first payment the interest would be (APR/periods)*principle or (.10/2)*100 = $5. Assuming you paid $55 (1/2 the principle plus the interest) the final payment would be $52.50 because the principle would now be only $50. So the interest would be calculated as thus: (.10/2)*50 = $2.50

Link to comment
https://forums.phpfreaks.com/topic/39797-intrest-monthly-plan/#findComment-192221
Share on other sites

... There are four variables involved:

 

$principle: the loan amount

$months: number of months (or periods) to pay off the loan

$apr: Annual percentage rate

 

 

 

There are also 3 types of programmer,

 

- Those that can count

- those that can't.

 

:D

Link to comment
https://forums.phpfreaks.com/topic/39797-intrest-monthly-plan/#findComment-192580
Share on other sites

... There are four variables involved:

 

$principle: the loan amount

$months: number of months (or periods) to pay off the loan

$apr: Annual percentage rate

 

 

 

There are also 3 types of programmer,

 

- Those that can count

- those that can't.

 

:D

 

Well, there were 4 variables when I started to write that response. But, then I realized that my variable $rate was a derivative of $apr and was not really a "unique" variable so I removed it.

 

And, since we are pointing out mistakes, you should have stated "There are also three types of programmers..."

 

It's all good!

Link to comment
https://forums.phpfreaks.com/topic/39797-intrest-monthly-plan/#findComment-192701
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.