Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calculate porcent

    hello guys this is my first post and need helps to calculate the percentage of a quantity
    example: I have 5000 and loan rioja with a rate of 10% a month this should give 5500, that 500 is 10% of 500. must have two options years and months
    try http://www.csgnetwork.com/simpleinterest.html

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    10% a month?

    Simple or compound interest?

    The skeleton of a simple interest calculation is:-


    Code:
    Principal Amount <input type ="text" size = "6" id = "princ"><br>
    Number of Periods <input type = "text" size = "6" id = "perd"><br>
    Interest Rate Per Period % <input type = "text" size = "6" id = "int"><br>
    Repayable <input type = "text" size = "6" id = "repay"><br><br>
    <input type = "button" value = "Calculate" onclick = "calc()">
    
    
    <script type = "text/javascript">
    function calc() {
    var p = parseFloat(document.getElementById("princ").value);
    var n = parseFloat(document.getElementById("perd").value);
    var r = parseFloat(document.getElementById("int").value);
    r = r/100;
    var period = p * r;
    document.getElementById("repay").value = (p + (period*n)).toFixed(2);
    }
    
    </script>
    But for practical use you will need to validate the inputs as positive numbers.

    The time is periods, and the interest is expressed per period. If you want 2 years 4 months at 10% a month, enter 28 periods.


    Quizmaster: In seafood on a restaurant menu, the French word "poisson" translates into English as what?
    Contestant: Chicken
    Last edited by Philip M; 03-11-2009 at 08:55 PM.

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you very much for reply philip m but I want to have the option months / years since 5000 if they borrow at 10% x 1 years should 11000.00
    ! is for a school project!

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by isidroca View Post
    thank you very much for reply philip m but I want to have the option months / years since 5000 if they borrow at 10% x 1 years should 11000.00
    ! is for a school project!
    Read the forum rules regarding homework. If you want further assistance you must post your own code.

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thax this my code

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.1 Transitional//EN">

    <HTML>
    <HEAD>
    <title>Simple Interest Amount Calculator</title>
    <script LANGUAGE="JavaScript">
    function perRound(num, precision) {

    var precision = 3; //default value if not passed from caller, change if desired

    // remark if passed from caller

    precision = parseInt(precision); // make certain the decimal precision is an integer

    var result1 = num * Math.pow(10, precision);

    var result2 = Math.round(result1);

    var result3 = result2 / Math.pow(10, precision);

    return zerosPad(result3, precision);

    }

    function zerosPad(rndVal, decPlaces) {

    var valStrg = rndVal.toString(); // Convert the number to a string

    var decLoc = valStrg.indexOf("."); // Locate the decimal point

    // check for a decimal

    if (decLoc == -1) {

    decPartsecnum = 0; // If no decimal, then all decimal places will be padded with 0s

    // If decPlaces is greater than zero, add a decimal point

    valStrg += decPlaces > 0 ? "." : "";

    }

    else {

    decPartsecnum = valStrg.secnumgth - decLoc - 1; // If there is a decimal already, only the needed decimal places will be padded with 0s

    }

    var totalPad = decPlaces - decPartsecnum; // Calculate the number of decimal places that need to be padded with 0s

    if (totalPad > 0) {

    // Pad the string with 0s

    for (var cntrVal = 1; cntrVal <= totalPad; cntrVal++)

    valStrg += "0";

    }

    return valStrg;

    }

    // send the value in as "num" in a variable
    // clears number of time periods field if changed

    function clear_field(field) {

    var timep = document.simpint.time.value;
    document.simpint.timeper.value='';
    document.simpint.timeper.value=timep;

    }

    // data definitions

    function checnum(as)
    {
    var dd = as.value;

    if(isNaN(dd))
    {
    dd = dd.substring(0,(dd.length-1));
    as.value = dd;
    }
    }


    function CalcSInt()
    {
    var ty = 4;
    var si = document.simpint.siamt.value;
    var p = document.simpint.amount.value;
    var r = document.simpint.simpinrate.value;
    var t = document.simpint.timeper.value;
    var ti = document.simpint.time.value;

    if(ty == 4)
    {
    t=t/ti;
    p = (si*100)/(r*t);
    document.simpint.siamt.value=p;
    }

    return false;
    }

    function modf()
    {
    for(var h=1; h<5; h++)
    {
    var dd = "document.simpint.res"+h;
    ss = eval(dd);
    }
    var vv = document.simpint.ss.value;
    var dd = "document.simpint.res"+vv;
    ss = eval(dd);
    ss.disabled=true;
    ss.value="";
    }

    </SCRIPT>

    </HEAD>

    <center>

    <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">

    <BODY BGCOLOR=FFFFFF TEXT=000000 LINK=0000FF VLINK=800080>

    <TABLE ALIGN=MIDDLE BORDER=5 CELLPADDING=5>

    <TR BGCOLOR=#FFFFFF>
    <TD WIDTH=80%><br />

    <center>

    <TABLE ALIGN=MIDDLE BORDER=0 CELLPADDING=5>

    <TR BGCOLOR=#B6D4D2>

    <!--ROW 1-->

    <TD WIDTH=80%><br>



    <br>

    <center>

    <TABLE ALIGN=MIDDLE BORDER=0 CELLPADDING=5>

    <TR BGCOLOR=#FFFFFF>


    </td>
    <!--ROW 1-->

    <TD WIDTH=80% VALIGN="CENTER">

    <center>

    <TABLE ALIGN=MIDDLE BORDER=0 CELLPADDING=5>

    <TR BGCOLOR=#FFFFFF>

    <!--ROW 1-->

    <TD WIDTH=80%>

    <center>

    <TABLE ALIGN=MIDDLE BORDER=0 CELLPADDING=5>

    <TR BGCOLOR=#B6D4D2>

    <!--ROW 1-->

    <td>

    <center>Unit</center>

    </td>

    <td>

    <center>Number</center>

    </td>

    </tr>

    <TR BGCOLOR=#B6D4D2>

    <TD align="center" colspan="2">

    Required Data Entry

    </td>

    </tr>
    <form name="simpint" method="post" onsubmit="return CalcSInt()">

    <TR>

    <TD>Principle (P)</TD>

    <TD>

    <INPUT type="text" size="18" NAME="amount" VALUE="10000.00" onKeyup="checnum(this)"> Dollars

    </TD>

    </TR>

    <TR>

    <TD>Interest Rate (R)</TD>

    <TD>

    <INPUT type="text" size="18" NAME="simpinrate" VALUE="5" onKeyup="checnum(this)"> % Per Annum

    </TD>

    </TR>

    <TR>

    <TD>Time (T) <select name="time" onChange="clear_field(this)">
    <option selected value="1">Years</option>
    <option value="12">Months</option>
    </select>
    </TD>

    <TD>

    <INPUT type="text" size="18" NAME="timeper" VALUE="5" onKeyup="checnum(this)">
    </TD>

    </TR>

    <TR>

    <TD colspan="2" align="center">

    <INPUT type="submit" NAME="name" VALUE="Calculate">&nbsp;&nbsp;&nbsp;

    <input type="Reset" value="Clear Values">
    <br>


    </td>

    </tr>

    <TR BGCOLOR=#B6D4D2>

    <TD align="center" colspan="2">

    Calculated Results

    </td>

    </tr>

    <TR>

    <TD>Simple Interest (I)</TD>

    <TD>

    <INPUT type="text" size="18" NAME="siamt" VALUE="" readonly> Dollars

    </TD>

    </TR>

    </table>

    </form>

    </td>

    </tr>

    </table>



    </center>

    </td>

    </tr>

    </table>

    </center>
    </tr>

    </table>

    <br>

    </BODY>

    </HTML>

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Well, you seem to have that already.

    <TD>Time (T) <select name="time" onChange="clear_field(this)">
    <option selected value="1">Years</option>
    <option value="12">Months</option>
    </select>
    </TD>

    So adjust the formulae depending on whether Years or Months is selected (but what about a loan for 2 year 6 months?). But onchange will not be triggered unless the value changes, so you need:-

    <option selected value="0">Select Period</option>
    <option value="1">Years</option>
    <option value="12">Months</option>

    It might make more sense to make the Years option value = 12 and the Months option value = 1, and then calculate in months.


    Note that principal is so-spelled and is not the same as principle.

    Your function
    function zerosPad(rndVal, decPlaces) {
    can be replaced very simply by
    .toFixed(2) which will result in xx.xx.

    <script LANGUAGE="JavaScript"> is deprecated and obsolete. It often indicates old and poor-quality code. Use<script type = "text/javascript"> instead.


    At the moment I think that is as much help as you can reasonably expect - it is not a good idea if other people simply do your homework for you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •