2
$meses = 3;
$valor = 1000
$valor_parcela = $valor / $meses;
for ($i = 1;$i <= $meses; $i++) {
$date_sum_month = date('d/m/Y', strtotime("+{$i} month", strtotime($date)));
array_push($boletos, ["numero" => $i, "vencimento" => date_sum_month, "valor" => $valor_parcela]);
}
return json_encode($boletos);
Result of my code:
1 - 333,333
2 - 333,333
3 - 333,333
Desired:
1 - 333
2 - 333
3 - 334
Use floor method: https://www.php.net/manual/en/function.floor.php
– Maury Developer
André, check if
$valor_parcela = floor($valor / $meses);
solves your problem if yes, explain to you in the answer– Luiz Augusto
Luiz Augusto did, but the floor rounds to less. doc: floor - Round fractions down
– André Cabral