Skip to content

Instantly share code, notes, and snippets.

@zokis
Last active August 29, 2015 14:23
Show Gist options
  • Save zokis/b9379b8d42f139ae9ffb to your computer and use it in GitHub Desktop.
Save zokis/b9379b8d42f139ae9ffb to your computer and use it in GitHub Desktop.
calcula parcelas
from decimal import Decimal
from math import floor
def parcelas(valor, n):
formato = Decimal('0.00')
valor = Decimal(valor)
parcela = Decimal(floor(valor * 100 / n) / 100).quantize(formato)
if parcela * n < valor:
parcelas = [parcela] * (n - 1)
parcelas.append((valor - sum(parcelas)).quantize(formato))
else:
parcelas = [parcela] * n
return parcelas
ps = parcelas(8.01, 4)
print ps
print sum(ps)
@zokis
Copy link
Author

zokis commented Jun 30, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment