Skip to content

Instantly share code, notes, and snippets.

@djfroofy
Created May 28, 2012 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djfroofy/2819940 to your computer and use it in GitHub Desktop.
Save djfroofy/2819940 to your computer and use it in GitHub Desktop.
LUA Mortgage payment calculator
#!/usr/bin/env lua
function monthly_payment(principal, apr, years)
local i = apr / 12
local n = years * 12
return principal * (i + (i / ((1 + i)^n - 1)))
end
local principal = tonumber(arg[1])
local apr = tonumber(arg[2]) / 100
local years = tonumber(arg[3])
print(string.format("%2.2f", monthly_payment(principal, apr, years)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment