Ver Mensaje Individual
  #7 (permalink)  
Antiguo 05/09/2008, 12:08
rociovt
 
Fecha de Ingreso: septiembre-2008
Mensajes: 15
Antigüedad: 16 años, 6 meses
Puntos: 0
Respuesta: duda de poner decimales en javascript

Cita:
Iniciado por David el Grande Ver Mensaje
Exacto, eso lo había entendido, es que lo que no entendía al principio es para qué agregar un cero si la posición era igual a 2 decimales, pero mirando mejor, si es longitud - 2 realmente faltaría un 0, por lo que al fin entendí .

En Javascript sería más o menos así:
Código PHP:
function ponerdecimales(numero)
{
if(
numero.indexOf(".")==-1)  { numero += ".00" } else {
   if(
numero.indexOf(".") == numero.length 2) { numero += "0" }
}
return 
numero;



ai que pena contigo pero me da un error no se porque me dice que se esperaba un objeto
mira aqui te enseño lo que estoy haciendo para que lo entiendas mejor.

<script language="javascript" type="text/javascript">

function calcularsubtotal()
{
var subtotal=0;



subtotal+= document.getElementById ("terminal1").value * 3940;
subtotal+= document.getElementById ("terminal2").value * 4650;
subtotal+= document.getElementById ("totem").value * 250;
subtotal+= document.getElementById ("rotulo").value * 250;
subtotal+= document.getElementById ("billetero").value * 410;
subtotal+= document.getElementById ("lector").value * 175;
subtotal+= document.getElementById ("puestam").value * 150;

var iva= subtotal * 16/100;
var total= subtotal + iva;



document.getElementById ("subtotal").innerHTML=subtotal;
document.getElementById ("iva").innerHTML=iva;
document.getElementById ("total").innerHTML=total;



var euro= "€";

document.getElementById ("t1").innerHTML= ponerdecimales(document.getElementById ("terminal1").value * 3940 ) + euro;
document.getElementById ("t2").innerHTML=ponerdecimales(document.getElemen tById ("terminal2").value * 4650) + euro;
document.getElementById ("tot").innerHTML=ponerdecimales(document.getEleme ntById ("totem").value * 250 + euro;
document.getElementById("rotu").innerHTML=ponerdec imales(document.getElementById ("rotulo").value * 250 + euro;
document.getElementById ("bille").innerHTML=ponerdecimales(document.getEle mentById ("billetero").value * 410 + euro;
document.getElementById ("lect").innerHTML=ponerdecimales(document.getElem entById ("lector").value * 175 + euro;
document.getElementById ("puest").innerHTML=ponerdecimales(document.getEle mentById ("puestam").value * 150 + euro;

}

aqui tambien te dejo una de las lineas del formulario

<td><input type="text" id="terminal1" name="terminal1" size="5" value="0" onChange="if (this.value!='') {calcularsubtotal();}">

a ver que me dice porque esta funcion me tiene mareada

si no gracias por todo ehh!!!






function ponerdecimales(numero)
{
if(numero.indexOf(".")==-1) { numero += ".00" } else {
if(numero.indexOf(".") == numero.length - 2) { numero += "0" }
}
return numero;
}


</script>