1 - 165.25
2 - 165.25
3 - 165.25
4 - 165.25
5 - 165.25
6 - 165.25
7 - 165.25
8 - 165.25
9 - 165.25
10 - 165.25
How to calculate .25 from all 10 amounts (0.25x10) = 2.5 and add that amount to the last value like this:
1 - 165
2 - 165
3 - 165
4 - 165
5 - 165
6 - 165
7 - 165
8 - 165
9 - 165
10 - 167.5
code
$amount = 165.25; // can be any number
$periods = 10; // can be from 1 to 100;
for($i=1;$i<=$periods;$i++){
echo $i. ' - '.$amount."<br />";
}
UPDATE Working example:
$amount = 165.25; // can be any number
$periods = 10; // can be from 1 to 100;
$z = 0;
for($i=1;$i<=$periods;$i++){
$e = explode(".", $amount);
$z += $e[1] / 100;
if($i == $periods){
$e[0] += $z;
}
echo $i. ' - '.$e[0]."<br />";
}
I don't like explode part any alternatives ?
$amount = 165.25;
$tmp = 0;
for($i=1;$i<=9;$i++){
$tmp = $tmp + $amount - floor($amount);
echo $i. ' - '.floor($amount)."<br />";
}
echo $i. ' - '.$amount+$tmp."<br />";
$total = 0;
for($i=1;$i<=10;$i++){
$total += $amount - floor($amount);
if($i == 10){
echo $i . ' - ' . (floor($amount) + $total);
}else{
echo $i. ' - '. floor($amount)."<br />";
}
}
something like this?