Round up instalment values for the first instalment

Asked

Viewed 999 times

2

For example:

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

Besides not making it easy, you’d be charging the customer an extra penny.

I would need a solution such as:

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

To facilitate the change of sales by crediario, how to arrendondar the value of the decimals for first installment , using Javascript?

  • 2

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

  • For this I use a logic similar to @Jorgeb. using the method allocate library bigmoney.js

  • understood the logic @Jorgeb have to post some example?

  • Look at my answer.

  • 1

    great @Jorgeb. I managed to apply perfectly in my code, thank you!

1 answer

3


Just divide 200 by 3 that gives 66.67, remove the decimal part, is then 66. And then add to one of the parcels the rest of the division 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

Browser other questions tagged

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