estoy tratando de crear un formulario que me pueda calcular el promedio de dos notas, asta el momento lo he logrado pero aparece con dos decimales y yo lo quiero con uno.
la idea es que si da 6.75 lo aprocxime a 6.8 etc. mis codigos son los sigientes;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<style type="text/css">
<!--
.Estilo1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.Estilo2 {color: #FFFFFF}
-->
</style>
</head>
<p align="center">
<script language="JavaScript" type="text/javascript">
function dp(price)
{
string = "" + price;
number = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.0';
if (number == 1)
return string + '0';
if (number == 1)
return string + '0';
if (number > 2)
return string.substring(0,string.length-number+4);
return string;
}
function calculate5()
{
dp (1.0)* document.calcform5.quantity15.value
dp (1.0)* document.calcform5.quantity25.value
document.calcform5.subtotal5.value = dp((eval(document.calcform5.quantity15.value) + eval(document.calcform5.quantity25.value))/2)
}
</script>
<style type="text/css">
<!--
.Estilo4 {font-size: 12px; }
-->
</style>
</HEAD>
</p>
<body>
<form name="calcform5" class="Estilo1" id="calcform5">
<table width="681" border="1" align="center" bordercolor="#000000">
<tbody>
<tr>
<td width="597"><p> </p>
</td>
<td width="68"><select name="quantity15" size="1" onchange="calculate5()" type="text">
<option>selec...</option>
<option value="7">7.0</option>
<option value="6.5">6.5</option>
<option value="6">6.0</option>
<option value="5.5">5.5</option>
<option value="5">5.0</option>
<option value="4.5">4.5</option>
<option value="4">4.0</option>
<option value="3.5">3.5</option>
<option value="3">3.0</option>
<option value="2">2.0</option>
<option value="1">1.0</option>
</select></td>
</tr>
<tr>
<td> </td>
<td><select name="quantity25" size="1" onchange="calculate5()" type="text">
<option>selec...</option>
<option value="7">7.0</option>
<option value="6.5">6.5</option>
<option value="6">6.0</option>
<option value="5.5">5.5</option>
<option value="5">5.0</option>
<option value="4.5">4.5</option>
<option value="4">4.0</option>
<option value="3.5">3.5</option>
<option value="3">3.0</option>
<option value="2">2.0</option>
<option value="1">1.0</option>
</select></td>
</tr>
<tr>
<td><div align="right"><strong>NOTA FINAL </strong></div></td>
<td><input name="subtotal5" id="subtotal5" value="0.0" size="7" /></td>
</tr>
</tbody>
</table>
</form>
</body>
</p>
</html>