Created
April 6, 2023 19:26
-
-
Save danyelhenrique/5289b57de7142497cef312f7cd2f6501 to your computer and use it in GitHub Desktop.
Formula PGTO
This file contains hidden or 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
| function pgto(tax, period, currentValue, valueFuture, type) { | |
| let pmt, currentValueIf; | |
| valueFuture || (valueFuture = 0); | |
| type || (type = 0); | |
| if (tax === 0) | |
| return -(currentValue + valueFuture) / period; | |
| currentValueIf = Math.pow(1 + tax, period); | |
| pmt = | |
| (-tax * (currentValue * currentValueIf + valueFuture)) / (currentValueIf - 1); | |
| if (type === 1) | |
| pmt /= (1 + tax); | |
| return pmt; | |
| } | |
| let tax = 2.04/100; | |
| let period = 5; | |
| let currentValue = 500; | |
| let pmt = pgto(tax, period, currentValue).toFixed(2) * -1; | |
| console.log(pmt); // <- Log result |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Formula PGTO in Javascript