#29 Calculating Loan Payments

In addition to temperature conversion, another common calculation for your users might well deal with estimating the size of loan payments. This script helps answer the question, "What can I do with that bonus?" — at least when things are going well.

While the formula to calculate payments based on the principal, interest rate, and duration of the loan is a bit tricky, some judicious use of shell variables tames the beast and makes it surprisingly understandable too.

The Code

 #!/bin/sh # loancalc - Given a principal loan amount, interest rate, and # duration of loan (years), calculates the per-payment amount. # Formula is: M = P * ( J / (1 - (1 + J) ** -N)) # where P = principal, J = monthly interest rate, N ...

Get Wicked Cool Shell Scripts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.