Shell script for loan calculation

Source: Internet
Author: User
The shell script for loan calculation aims to further understand mathematical computing in terms of temperature conversion. Code: 01 #! /Bin/sh0203 # loancalc. sh -- specify the loan principal, tax rate, and period of 0405 # formula: MP * (J/(1-(1 + J) **-N) 06 # its... the shell script for loan calculation aims to further understand mathematical computing in terms of temperature conversion. Code: 01 #! /Bin/sh02 03 # loancalc. sh -- specify the loan principal, tax rate, and period 04 05 # formula: M = P * (J/(1-(1 + J) **-N) 06 # where, P = Principal, J = monthly tax rate, N = years (months) 07 # User input P, I (annual interest rate), L (length, year) 08 09 # note, the (1 + J) **-N behind the formula is a whole, indicating the index 10 # for example, (1 + 1) **-2 is 2 ^-2, equivalent to 1/2*2 = 0.2511 12 # source library. sh13 14if [$ #-ne 3]; then15 echo "Usage: 'basename $ 0' principal interest loan-duration-years"> & 216 exit 117fi18 19 # scriptbc used here. sh is the ninth script of the program 2 0 # The parameter passed to it is a formula, and some operator numbers need to be escaped. 21 # Escape :() * ^ 22 P = $1 I = $2 L = $ 323J = "$ (scriptbc. sh-p 8 $ I/\ (12 \ * 100 \) "24N =" $ ($ L * 12) "25 M =" $ (scriptbc. sh-p 8 $ P \ * \ ($ J/\ (1-\ (1 + $ J \) \ ^-$ N \)\)) "26 27 dollars =" $ (echo $ M | cut-d. -f1) "28 cents =" $ (echo $ M | cut-d. -f2 | cut-C1-2) "29 30 # newnicenum. sh is the 31cat program in the 4th scripts <EOF32A $ L year loan at $ I % interest with a principal amount of $ (newnicenum. sh $ P 1) 33 results in a payme Nt of \ $ dollars. $ cents each month for the duration of34the loan ($ N payments ). 35EOF36 37 exit 0 running result: 1 $ loancalc 40000 6.75 42A 4 year loan at 6.75% interest with a principal amount of 953.21 results in a payment of $ each month for the duration of4the loan (48 payments ). 5 6 $ loancalc 40000 6.75 57A 5 year loan at 6.75% interest with a principal amount of 787.33 results in a payment of $ Each month for the duration of9the loan (60 payments). analysis script: this script shows a complete mathematical formula operation.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.