Round off installment values for the first installment

2

For example:

venda de R$ 200,00 em 3x:
parc 1: 66,67
parc 2: 66,67
parc 3: 66,67

In addition to not making the change easier, it would be charging a penny more.

You would need a solution such as:

parc 1: 68,00
parc 2: 66,00
parcl 3: 66,00

To facilitate sales changes by the store, how to round the value of the decimal places for the first installment using Javascript?

    
asked by anonymous 20.01.2015 / 14:19

1 answer

3

Just divide 200 by 3 that gives 66.67, remove the decimal part, then 66. And then add to one of the plots the remainder of the division by 200 by 3.

Basic example:

<?php
$value = 200;
$prest = 3;
$div   = (int) ($value / $prest);
$resto = $value % $prest;
$init  = $prest-1;
$fin   = $div+$resto;

echo "De {$value} tem de pagar {$init} prestações de {$div} e 1 prestação de {$fin}"; 
?>

Running on PhpFiddle

    
20.01.2015 / 16:24