Código PHP:
<script>
function dp(price)
{
string = "" + price;
number = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (number == 1)
return string + '00';
if (number == 2)
return string + '0';
if (number > 3)
return string.substring(0,string.length-number+5);
return string;
}
function calculate()
{
document.calculo.trimestre.value = dp((document.calculo.montoanual1.value)*(document.calculo.cantidad.value)/4)
document.calculo.montoanual1.value = dp((document.calculo.Vinmueble.value)*(document.calculo.escala.value)/100)
document.calculo.t1.value = dp((document.calculo.t2.value)-(document.calculo.t2.value)*(document.calculo.Ut1.value)/100-(document.calculo.dt1.value))
document.calculo.t2.value = dp((document.calculo.t3.value)-(document.calculo.t3.value)*(document.calculo.Ut2.value)/100-(document.calculo.dt2.value))
document.calculo.t3.value = dp((document.calculo.t4.value)-(document.calculo.t4.value)*(document.calculo.Ut3.value)/100-(document.calculo.dt3.value))
document.calculo.t4.value = dp((document.calculo.t5.value)-(document.calculo.t5.value)*(document.calculo.Ut4.value)/100-(document.calculo.dt4.value))
document.calculo.t5.value = dp((document.calculo.t6.value)-(document.calculo.t6.value)*(document.calculo.Ut5.value)/100-(document.calculo.dt5.value))
document.calculo.t6.value = dp((document.calculo.montoanual1.value)-(document.calculo.montoanual1.value)*(document.calculo.Ut6.value)/100)
document.calculo.suma1.value = dp(eval(document.calculo.t1.value) + eval (document.calculo.t2.value)+ eval (document.calculo.t3.value)+ eval (document.calculo.t4.value)+ eval (document.calculo.t5.value)+ eval (document.calculo.t6.value))
document.calculo.multa1.value = dp((document.calculo.suma1.value)*(document.calculo.multa.value)/100)
document.calculo.total.value = dp(eval(document.calculo.suma1.value)+ eval (document.calculo.multa1.value)+ eval (document.calculo.trimestre.value))
}
</script>