Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/01/2010, 12:11
expecimen
 
Fecha de Ingreso: octubre-2006
Ubicación: Ciudad Ojeda, Venezuela
Mensajes: 123
Antigüedad: 17 años, 6 meses
Puntos: 0
Busqueda calculo que arroje solo dos decimales

hola a todos de nuevo, tengo un formulario de calculo que trabaja muy bien pero estoy tratando de que solo me arroje solo dos decimales por ejemplo:

305.33
25.69

el hace los calculo pero me arroja resultados de tres decimales y el script que tengo que pasa de números a letras no me lee los tres decimales sino que lee la a aproximación ejemplo:

99.928 = Noventa y Nueve con Noventa y tres céntimos (99.93)

en si lo que quiero es que me de los resultados en dos decimales o dos centimos, dejo el codigo para que también lo puedan usar... funciona bien pero no da los resultados en dos decimales como to quiero:

Código PHP:

<head>
<
title>calculos</title>
<
script>

function 
dp(price
{
   
string "" price;
   
number string.length string.indexOf('.');
   if (
string.indexOf('.') == -1)
      return 
string '.00';
   if (
number == 0)
      return 
string '00';
   if (
number == 0)
      return 
string '.0';
   if (
number == 0)
      return 
string.substring(-2,string.length-number-2);
return 
string;
}

function 
calculate()
{
document.loginForm.total1.value dp((document.loginForm.puesto.value)* 70 + eval(document.loginForm.peso.value))
document.loginForm.total2.value 360
document
.loginForm.total3.value dp((document.loginForm.quantity3.value))
document.loginForm.subtotal.value dp(eval(document.loginForm.total1.value) * (document.loginForm.total2.value) * (document.loginForm.total3.value)*(document.loginForm.canios2.value))
document.loginForm.tax.value dp((document.loginForm.subtotal.value)/1000)
document.loginForm.total.value dp((document.loginForm.subtotal.value)/1000 + eval(document.loginForm.tasa.value))
}

</script>
</head>

<body bgcolor="#ffffff" onload="calculate" topmargin="0">

<center>
<form name="loginForm" action="mailto:[email protected]" method="post">
    <table border="0" width="98%" cellspacing="1">
        <tr>
            <td width="493" height="6" colspan="2"></td>
            <td width="168" height="6"></td>
            <td width="236" height="6"></td>
            <td width="179" height="6"></td>
        </tr>
        <tr>
            <td width="248"><b><font face="Tahoma" size="2">Ultimo año LPV:</font></b></td>
            <td width="241"><b><font face="Tahoma" size="2">Año a procesar:</font></b></td>
            <td width="168"><b><font face="Tahoma" size="2">Tipo:</font></b></td>
            <td width="236"><b><font size="2" face="Tahoma">Proceso de:</font></b></td>
            <td width="179">&nbsp;</td>
        </tr>
        <tr>
            <td width="248">
            <select size="1" name="canios2" style="border: 1px solid #000000">
            <option value="1">2009</option>
            <option value="2">2008</option>
            <option value="3">2007</option>
            <option value="3">2006</option>
            <option value="3">2005</option>
            </select></td>
            <td width="241">
            <select size="1" name="canios3" style="border: 1px solid #000000">
            <option value="2010" selected>2010</option>
            </select></td>
            <td width="168">
            <select size="1" name="quantity3" style="border: 1px solid #000000">
            <option value="0.10" selected>PARTICULAR</option>
            <option value="0.05">COLECTIVO</option>
            <option value="0.15">CARGA</option>
            <option value="0.05">OTROS</option>
            <option value="0.00">EXONERADO</option>
            </select></td>
            <td width="236" align="justify">
            <select size="1" name="proce" style="border: 1px solid #000000">
            <option value="INSCRITO" selected>INSCRIPCION</option>
            <option value="RENOVADO">RENOVACION</option>
            </select></td>
            <td width="179">
            <input type="text" name="total1" readonly="readonly" size="13"></td>
        </tr>
        <tr>
            <td width="247"><b><font size="2" face="Tahoma"># Puesto:</font></b></td>
            <td width="246"><b><font size="2" face="Tahoma">Peso:</font></b></td>
            <td width="168"><b><font size="2" face="Tahoma">Tasa:</font></b></td>
            <td width="236">&nbsp;</td>
            <td width="179">
            <input type="text" name="total2" readonly="readonly" size="13"></td>
        </tr>
        <tr>
            <td width="247">
            <input type="text" name="puesto" onchange="calculate()" size="8" style="border: 1px solid #000000"></td>
            <td width="246">
            <input type="text" name="peso" onchange="calculate()" size="8" style="border: 1px solid #000000">
            <b><font size="2" face="Tahoma">Kgs.</font></b></td>
            <td width="168">
            <input type="text" name="tasa" onchange="calculate()" size="3" value="1" style="text-align: center; border: 1px solid #000000"></td>
            <td width="236">
            &nbsp;</td>
            <td width="179">
            <input type="text" name="total3" readonly="readonly" size="13"></td>
        </tr>
        <tr>
            <td width="493" colspan="2">&nbsp;</td>
            <td width="168">&nbsp;</td>
            <td align="right">
            <p style="margin-right: 8px"><b><font face="Tahoma" size="2">Sub 
            Total:</font></b></p>
            </td>
            <td width="179">
            <input type="text" name="subtotal" readonly="readonly" size="13"><font size="2" face="Tahoma">Bs.</font></td>
        </tr>
        <tr>
            <td width="493" colspan="2">&nbsp;</td>
            <td width="168">&nbsp;</td>
            <td align="right">
            <p style="margin-right: 8px"><b><font face="Tahoma" size="2">Incri/Renov:</font></b></p>
            </td>
            <td width="179">
            <input type="text" name="tax" readonly="readonly" size="13"><font size="2" face="Tahoma">Bs.</font></td>
        </tr>
        <tr>
            <td width="493" colspan="2"></td>
            <td width="168">&nbsp;</td>
            <td align="right">
            <p style="margin-right: 8px"><b>
            <font face="Tahoma" size="2" color="#FF0000">TOTAL:</font></b></p>
            </td>
            <td width="179">
            <input type="text" name="total" readonly="readonly" size="13" style="color: #FF0000"><font size="2" face="Tahoma">Bs.</font></td>
        </tr>
    </table>
</form>
</center>

</body>