Created
April 6, 2023 19:26
-
-
Save danyelhenrique/5289b57de7142497cef312f7cd2f6501 to your computer and use it in GitHub Desktop.
Revisions
-
danyelhenrique created this gist
Apr 6, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ 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