Last active
July 19, 2016 20:54
-
-
Save nerijunior/1257438c4466de3ce28c5312ceb5c756 to your computer and use it in GitHub Desktop.
Juros Compostos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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