Example - Ideone
$parcelas=11;
$segredo = (1 + $parcelas) * ($parcelas / 2);
$valor="R$ 1900,30";
//replace para retirar R$ e trim para retirar espaço
$preco=trim(str_replace("R$","",$valor));
//armazenando virgula centavos
$decimal= substr($preco,(strlen($preco)-3),strlen($preco));
//retirando virgula centavos
$preco=(str_replace($decimal,"",$preco));
//calculando valores das parcelas
for ($x = 1; $x <= ($parcelas-1); $x++) {
$parcela = intval((($preco*$x)/$segredo));
echo ("R$ ". number_format($parcela, 2, ',', '.'))."<br>";
$somatorio=$somatorio+$parcela;
}
//calculo da ultima parcela
$ultima=$preco-$somatorio;
echo ("R$ ".($ultima.$decimal));
Want to know what the variable is $segredo
? click on the interjection.
The variable $segredo
is the sum of the numbers from 1 to the number of plots. Generalizing, sum of the n first natural numbers.
DOCUMENTATION
Can you give some example with numbers? you want to do this in excel or with php?
– Sergio
did not understand this line "For example: PRODUCT PRODUCT VALUE X 700.00"
– Andrei Coelho
@Sergio For example, I have a product of R$ 1900,00 and I would like to divide it into 5 Installments. I’m doing it in PHP
– Bruno Cesar
@Andreicoelho I just tidied up, I hadn’t jumped the line.
– Bruno Cesar
Are there any rules to follow? For example, a product of R$ 100,00 in 3x could be 1 of 10,00, another of 0,01 and another of 89,99?
– Bruno Rigolon
@Brunorigolon, without rules, would be random values. For example, in the case of the Product of R$ 1900,00, a portion may be 100 reais and the others larger.
– Bruno Cesar
Can you describe the relationship between Excel and PHP? In fact, a lot of trivial information has already been given in the comments. Search [Dit] the question and make it clearer with all these details.
– Woss
@Andersoncarloswoss, I’m sorry! I expressed myself badly in the question. I will edit
– Bruno Cesar