Skip to content

Instantly share code, notes, and snippets.

@nerijunior
Last active July 19, 2016 20:54
Show Gist options
  • Save nerijunior/1257438c4466de3ce28c5312ceb5c756 to your computer and use it in GitHub Desktop.
Save nerijunior/1257438c4466de3ce28c5312ceb5c756 to your computer and use it in GitHub Desktop.
Juros Compostos
class JurosCompostos {
constructor(capital, taxa, tempo, nomeTempo) {
this.capital = capital
this.taxa = taxa / 100
this.tempo = tempo
this.nomeTempo = nomeTempo
this.total = 0
this.totalJuros = 0
// Init
this.calcularValorTotalNoPeriodo()
this.calcularValorTotalDeJuros()
}
calcularValorTotalDeJuros() {
this.totalJuros = ((Math.pow((1 + this.taxa), this.tempo)) - 1) * 100
}
calcularValorTotalNoPeriodo() {
this.total = this.capital * Math.pow((1 + this.taxa), this.tempo)
return this
}
get diferenca() {
return this.total - this.capital
}
get valorParcela() {
return this.total / this.tempo
}
}
var juros = new JurosCompostos(6000, 4, 6, 'meses')
console.info('Valor corrigido após o período: ', numberFormat(juros.total));
console.log('Valor da parcela: ', numberFormat(juros.valorParcela))
console.log('Diferença paga: ', numberFormat(juros.diferenca))
console.log('Total de Juros: ', juros.totalJuros, '%')
function numberFormat(value) {
return value.toLocaleString('pt-BR', {
style: 'currency',
currency: 'BRL'
})
}
/**
* Cálculo de Juros compostos
*/
let M = 0 // Montante
let C = 0 // Capital
let i = 0 // Taxa
let t = 0 // Tempo
// R$ 20.000,00 em 3 anos com taxa de 20% ao ano
C = 20000
i = 0.2
t = 3
M = C * Math.pow((1 + i), t)
console.log('Valor corrigido após o período: ', M.toLocaleString('pt-BR', { style: 'currency', currency: }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment