This library provides basic finance methods to compute finance amortization schedules, payment amounts, number and currency formatting. Methods are provided to obtain the payment, interest rate, amount financed, or months financed given 3 of any of the 4.
Finance.js has no dependencies and may be used by itself. Back to TrentRichardson.com
Finance.js was contributed by the excellent CarBounce App.You can download, fork, and issue pull requests on GitHub.
Three parameters: amount, months, interest rate (percent)
finance.calculatePayment(25000, 60, 5.25);
Three parameters: months, interest rate (percent), payment
finance.calculateAmount(60, 5.25, 474.65);
Three parameters: amount, interest rate (percent), payment
finance.calculateMonths(25000, 5.25, 474.65);
Three parameters: amount, months, payment
finance.calculateInterest(25000, 60, 474.65);
If your money is in a bank account accruing interest, how much does it earn over x months? Three parameters: principle amount, months, interest rate (percent)
finance.calculateAccruedInterest(25000, 60, 5.25);
Create an amortization schedule. The result should be an array the length the number of months. Each entry is an object. Four parameters: principle amount, months, interest rate (percent), start date (optional Date object)
finance.calculateAmortization(25000, 60, 5.25, new Date(2011,11,20) );
One parameters: number
finance.format(-2530023420269.123456);
Format a number with a certain precision. Two parameters: number, settings (optional, 'number')
finance.format(25000.123456, {precision:2});
Format a number to a certain currency. Two parameters: number, settings (optional). If settings option is a string it is treated as a currency name. If it is an object it is used as currency settings.
finance.format(25000.123456, 'USD');
Settings can be format, and then override with options.
finance.format(-25000.123456, 'GBP', { negative: '()', precision: 3, thousand: '' });
Format a number with a certain precision. Two parameters: number, settings ("percent" is a format)
finance.format(25000.123456, 'percent');
You may create a currency. The library comes with "USD", "GBP", and "EUR" currency formats and "number" and "percent" numeric formats. To set the default currency set finance.settings.format to your preference. Two parameters: key, settings
finance.addFormat('Dollars', { before: '', after: ' Dollars', precision: 0, thousand: ',', group: 3, decimal: '.', negative: '-' });
Use the new currency
finance.format(25000.123456, 'Dollars');
To remove a currency. One parameter: key
finance.removeFormat('Dollars');
You may use this project under MIT or GPL licenses.