Calculating Values of Different Plots

Asked

Viewed 617 times

0

Guys, I have a spreadsheet in Excel with several lines with Product values.

I will import these values into Mysql.

For example:
PRODUCT VALUE
PRODUCT X R$ 700,00

I need to divide this $ 700,00 in X installments, but these installments can not have equal amounts ... Someone can help me ?

  • Can you give some example with numbers? you want to do this in excel or with php?

  • did not understand this line "For example: PRODUCT PRODUCT VALUE X 700.00"

  • @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

  • @Andreicoelho I just tidied up, I hadn’t jumped the line.

  • 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?

  • @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.

  • 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.

  • @Andersoncarloswoss, I’m sorry! I expressed myself badly in the question. I will edit

Show 3 more comments

1 answer

1

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

  • I liked your reply @Leocaracciolo. But what if it’s 12 installments? Or 11?

  • @Andrei Coelho, if liked paid :) I edited the question for any amount of installments.

  • Rsrs... now yes. =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.