Skip to content

Instantly share code, notes, and snippets.

@williankeller
Last active August 21, 2018 11:53
Show Gist options
  • Select an option

  • Save williankeller/779a20dd0c8f1c571a0e to your computer and use it in GitHub Desktop.

Select an option

Save williankeller/779a20dd0c8f1c571a0e to your computer and use it in GitHub Desktop.
<?php
public static function getAcrescimo($valor, $parcelas, $acrescimo)
{
if (!is_numeric($valor) || $valor <= 0) {
return false;
}
if ((int) $parcelas != $parcelas) {
return false;
}
if (!is_numeric($acrescimo) || $acrescimo < 0) {
return false;
}
$denominador = 0;
if ($parcelas > 1) {
for ($i = 1; $i <= $parcelas; $i++) {
$denominador += (1 / pow(1 + ($acrescimo / 100), $i));
}
} else {
$denominador = 1;
}
return ($valor / $denominador);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment