Skip to content

Calculation Only (JSON)

James Pederson edited this page May 17, 2014 · 4 revisions

Simple Loan Calculations

Simply need to run some loan numbers against the plugin to use in your own way? The $.loanInfo() function is public, so you can directly call it to perform a calculation and get a JSON response. Like so:

// calculate the loan info
var loan_info = $.loanInfo({
  amount: "$7,500",
  rate: "7%",
  term: "36m"
});

// log the calculation data for test purposes
console.log( loan_info );

The numbers in the snippet above are populated just as an example of the type of input this function could accept. The default values for all of the object properties is 0


Input Values

amount

The amount property can contain any characters. All but the numbers 0123456789 and dots . will be stripped out, so that no errors can occur - even when those wonderful users enter characters that have no place in math equations. 😄

rate

The rate property will get the same cleaning treatment as the amount, so no worries when it comes to bad math characters. The function expects the rate to be the Annual Percentage Rate.

term

The term property is treated differently than the other two properties. It will take values of either years or months, and will assume months. Specify these values by entering a number and then either m (months) or y (years) - though the letter is not required, and if only a number is passed, it's assumed to be a month count, or number of payments.


Response Format (JSON)

The call above would produce the following JSON response.

{
  num_payments:                 36,
  original_amount:              "7500",
  payment_amount:               231.5782264902889,
  payment_amount_formatted:     "231.58",
  total_interest:               836.8161536504012,
  total_interest_formatted:     "836.82",
  total_payments:               8336.816153650401,
  total_payments_formatted:     "8336.82"
}

For convenience and accuracy sake, the function returns both formatted and exact values of the calculation so you can pick yer poison.

Clone this wiki locally