...

# Calculate porcent

isidroca
03-11-2009, 09:30 PM
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

Philip M
03-11-2009, 09:51 PM
10% a month? :eek::eek:

Simple or compound interest?

The skeleton of a simple interest calculation is:-

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

isidroca
03-11-2009, 10:26 PM
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!

Philip M
03-12-2009, 09:16 AM
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.

isidroca
03-12-2009, 03:43 PM
thax this my code

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

<HTML>
<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);

}

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

// 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>

<center>

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

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

<center>

<TR BGCOLOR=#B6D4D2>

<!--ROW 1-->

<TD WIDTH=80%><br>

<br>

<center>

<TR BGCOLOR=#FFFFFF>

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

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

<center>

<TR BGCOLOR=#FFFFFF>

<!--ROW 1-->

<TD WIDTH=80%>

<center>

<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>

Philip M
03-12-2009, 04:05 PM
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.