forked from trentrichardson/FinanceJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
211 lines (178 loc) · 9.13 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Finance.js - Javascript Finance, Loan, and Currency Formatting Methods</title>
<meta name="Description" content="A javascript object with loan, finance, money and number formatting methods" />
<meta name="Keywords" content="javascript,calculator,loan,finance,interest,principle,format,money,currency,amortization,schedule" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="finance.js"></script>
<style type="text/css">
/*
------------------------------
layout
------------------------------
*/
body,img,p,h1,h3,fieldset,form,pre,code{ margin:0; padding:0; border:0; }
body {
font: 12px/16px Arial, Helvetica, sans-serif;
border-top: solid 5px #A04334;
background-color: #FAF9F4;
text-align: center;
}
noscript{ color: #ff0000; font-weight: bold; }
h1{ font-family: Times, serif; color: #555; margin: 0 0 20px -40px; letter-spacing: 2px; }
h2{ padding: 10px 25px; margin: 10px -65px; font-size: 1.75em; font-family: Helvetica, sans-serif; font-weight: normal; letter-spacing: 4px; text-transform: uppercase; color: #777; }
h3{ margin: 20px 0 0 0; font-size: 1.5em;}
p{ line-height: 18px; margin: 10px 0; }
a{ color: #7B94B2; }
a:hover{ color: #5B7492; }
#wrapper{ text-align: left; margin: 40px auto; background-color: #ffffff; width: 500px; min-height: 200px; padding: 25px 25px 25px 65px; }
div.example{ }
pre{ padding: 10px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px;}
pre.code{background-color: #333; color: #fff; overflow: auto;}
pre.result{ background-color: #bbb; color: #555; }
</style>
<script type="text/javascript">
$(document).ready(function(){
$('.example').each(function(){
var $t = $(this),
$code = $t.children('pre.code'),
$result = $t.children('pre.result');
if($result.length > 0){
var result = eval($code.text()),
output = '',
k = null;
if(result && result.constructor == Array){
output = '[\n\t';
for(var i=0; i<4; i++){
output += '{\n\t';
for(k in result[i])
if(result[i].hasOwnProperty(k))
output += '\t'+ k +': '+ result[i][k] +'\n\t';
output += '},\n\t';
}
output += '...\n]';
result = output;
}
$result.text(result);
}
});
var ePay = finance.calculateEarlyPayoff(24000, 5, 72, 72, 100, 386.52);
$('#earlyPay').text(ePay.saving + " " + ePay.years + "year " + ePay.months + "months");
});
</script>
</head>
<body>
<div id="wrapper">
<h1>Finance.js - Common Finance Functions</h1>
<p>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.</p>
<p>Finance.js has no dependencies and may be used by itself. <a href="http://trentrichardson.com/" title="Back to TrentRichardson.com">Back to TrentRichardson.com</a></p>
<a href="http://carbounce.com" title="Car Bounce" style="display: inline-block;width:350px;padding: 10px;background-color: #fbfbfb;border: dotted 4px #e8e8e8;color: #9EC45F;font-size: 16px;text-decoration:none;letter-spacing:1px;"><img src="http://carbounce.com/img/logo_small.png" alt="Car Bounce" align="left" style="margin-right: 20px;"/>Finance.js was contributed by the excellent CarBounce App.</a>
<h2>Download</h2>
<p>You can download, fork, and issue pull requests on GitHub.</p>
<p><a href="https://github.com/trentrichardson/FinanceJs" title="Download Finance.js on GitHub">Download Finance.js on Github</a></p>
<h2>Finance and Loan Functions</h2>
<div class="example">
<h3>Calculate the Financed Payment Amount</h3>
<p>Three parameters: amount, months, interest rate (percent)</p>
<pre class="code">finance.calculatePayment(25000, 60, 5.25);</pre>
<pre class="result"></pre>
</div>
<div class="example">
<h3>Calculate the Financed Amount</h3>
<p>Three parameters: months, interest rate (percent), payment</p>
<pre class="code">finance.calculateAmount(60, 5.25, 474.65);</pre>
<pre class="result"></pre>
</div>
<div class="example">
<h3>Calculate the Months Financed</h3>
<p>Three parameters: amount, interest rate (percent), payment</p>
<pre class="code">finance.calculateMonths(25000, 5.25, 474.65);</pre>
<pre class="result"></pre>
</div>
<div class="example">
<h3>Calculate the Financed Interest Rate</h3>
<p>Three parameters: amount, months, payment</p>
<pre class="code">finance.calculateInterest(25000, 60, 474.65);</pre>
<pre class="result"></pre>
</div>
<div class="example">
<h3>Calculate the Accrued Interest</h3>
<p>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)</p>
<pre class="code">finance.calculateAccruedInterest(25000, 60, 5.25);</pre>
<pre class="result"></pre>
</div>
<div class="example">
<h3>Create Amortization Schedule</h3>
<p>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)</p>
<pre class="code">finance.calculateAmortization(25000, 60, 5.25, new Date(2011,11,20) );</pre>
<pre class="result"></pre>
</div>
<div class="example">
<h3>Calculate Early Payoff</h3>
<p>Calculate how much money and time saved by paying early. Six parameters: principle amount, interest rate (percent), months, remaining months, additional monthly payment, current monthly payment</p>
<pre class="code">finance.calculateEarlyPayoff(24000, 5, 72, 72, 100, 386.52);</pre>
<pre class="result" id="earlyPay"></pre>
<p>This function will return an object with 3 values (saving, years, months), so it is recommended that you save the return to a variable. <br>
<br><strong>Calling the function:</strong>
<br>var result = finance.calculateEarlyPayoff(24000, 5, 72, 72, 100, 386.52);
<br><br>
<strong>Retrieving values:</strong>
<br>var totalSavings = result.saving;
<br>var shortenedYears = result.years;
<br>var shortenedMonths = result.months;
</p>
</div>
<h2>Currency Formatting</h2>
<div class="example">
<h3>Format a Number</h3>
<p>One parameters: number</p>
<pre class="code">finance.format(-2530023420269.123456);</pre>
<pre class="result"></pre>
</div>
<div class="example">
<p>Format a number with a certain precision. Two parameters: number, settings (optional, 'number')</p>
<pre class="code">finance.format(25000.123456, {precision:2});</pre>
<pre class="result"></pre>
</div>
<div class="example">
<h3>Format Currency</h3>
<p>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.</p>
<pre class="code">finance.format(25000.123456, 'USD');</pre>
<pre class="result"></pre>
</div>
<div class="example">
<p>Settings can be format, and then override with options.</p>
<pre class="code">finance.format(-25000.123456, 'GBP', { negative: '()', precision: 3, thousand: '' });</pre>
<pre class="result"></pre>
</div>
<div class="example">
<h3>Format a Percent</h3>
<p>Format a number with a certain precision. Two parameters: number, settings ("percent" is a format)</p>
<pre class="code">finance.format(25000.123456, 'percent');</pre>
<pre class="result"></pre>
</div>
<div class="example">
<h3>Create and Remove a Currency</h3>
<p>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</p>
<pre class="code">finance.addFormat('Dollars', { before: '', after: ' Dollars', precision: 0, thousand: ',', group: 3, decimal: '.', negative: '-' });</pre>
<pre class="result"></pre>
</div>
<div class="example">
<p>Use the new currency</p>
<pre class="code">finance.format(25000.123456, 'Dollars');</pre>
<pre class="result"></pre>
</div>
<div class="example">
<p>To remove a currency. One parameter: key</p>
<pre class="code">finance.removeFormat('Dollars');</pre>
<pre class="result"></pre>
</div>
<h2>License</h2>
<p>You may use this project under MIT or GPL licenses.</p>
<p><a href="http://trentrichardson.com/Impromptu/GPL-LICENSE.txt" title="GPL License">GPL License</a></p>
<p><a href="http://trentrichardson.com/Impromptu/MIT-LICENSE.txt" title="MIT License">MIT License</a></p>
</div>
</body>
</html>