Finance.js - Common Finance Functions

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

Car BounceFinance.js was contributed by the excellent CarBounce App.

Download

You can download, fork, and issue pull requests on GitHub.

Download Finance.js on Github

Finance and Loan Functions

Calculate the Financed Payment Amount

Three parameters: amount, months, interest rate (percent)

finance.calculatePayment(25000, 60, 5.25);

			

Calculate the Financed Amount

Three parameters: months, interest rate (percent), payment

finance.calculateAmount(60, 5.25, 474.65);

			

Calculate the Months Financed

Three parameters: amount, interest rate (percent), payment

finance.calculateMonths(25000, 5.25, 474.65);

			

Calculate the Financed Interest Rate

Three parameters: amount, months, payment

finance.calculateInterest(25000, 60, 474.65);

			

Calculate the Accrued Interest

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 Amortization Schedule

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) );

			

Currency Formatting

Format a Number

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 Currency

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 Percent

Format a number with a certain precision. Two parameters: number, settings ("percent" is a format)

finance.format(25000.123456, 'percent');

			

Create and Remove a Currency

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');

			

License

You may use this project under MIT or GPL licenses.

GPL License

MIT License