Generate plot values and dates in a datatable c#

Asked

Viewed 902 times

0

Hello,

I have a form where is placed a Total Sale Value, the Number of Installments of Payment. Then I would like my Datatable that is located in the other Form to present the values and the due dates with its value divided by the amount of months.

For example:

       Valor Total: 200

       Prazo: 3

Datatable has to appear:


 parcela    |  valor  | Data Vencimento
    01      |  66,67  |   02/02/2018
    02      |  66,67  |   02/03/2018
    03      |  66,67  |   02/04/2018

Can you understand my doubt? Could someone help me?

  • What is your specific question? the calculation?

  • Generation of calculation and maturity date for each installment... I want the output to be equal to the example shown

1 answer

4


Here is an example of a demonstration.

decimal valorTotal = 200.00M;
int numeroParcelas = 3;
DateTime dataPrimeiroVencimento = DateTime.Now;

decimal valorParcela = Math.Round(valorTotal / numeroParcelas, 2);
decimal valorDiferenca = valorTotal - valorParcela * numeroParcelas;    

for (int i = 0; i < numeroParcelas; i++)
{

    //Calculo dos valores;
    string parcela = (i + 1).ToString().PadLeft(2, '0');
    string valor = !(i + 1 == numeroParcelas) ? valorParcela.ToString() : (valorParcela + valorDiferenca).ToString();
    string dataVencimento = dataPrimeiroVencimento.AddMonths(i).ToShortDateString();


    //Exemplo do resultado
    Console.WriteLine(parcela + " | " + valor + " | " + dataVencimento);
}

Exit:

01 | 66,67 | 02/02/2018
02 | 66,67 | 02/03/2018
03 | 66,66 | 02/04/2018
  • 1

    Do not forget to treat the difference between the total value and the total sum of the plots. As is the case of R $ 100,00 / 3. The 0,01 cent remaining should be added in the final or initial installment.

  • 1

    Exactly, well placed @Lucasdesouzacruz, I’ll even add the treatment in the answer

Browser other questions tagged

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