
04/01/2007, 17:10
|
 | Moderador extraterrestre | | Fecha de Ingreso: diciembre-2001 Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 23 años, 2 meses Puntos: 61 | |
Re: Sumar decimales Dime si esto te serviría:
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Untitled</title>
<style>
.texto{
text-align:right;
font:normal 12px/12px 'courier new';
border:solid 1px black;
}
</style>
<script>
function sumar(){
campos=['pvd_batlarga','pvd_funda','pvd_protector'];
f=document.forms['f1'];
total=0;
g="";
anterior=0;
d=0;
for(a=0;a<campos.length;a++){
c=f[campos[a]].value;
c=c.split(".").join("");
c=c.split(",").join(".");
total+=parseFloat(c);
}
partes=String(total).split(".");
cifras=partes[0].length;
enteros=partes[0];
decimales=partes[1];
primerPunto=cifras%3;
primerPunto=(primerPunto==0)?3:primerPunto;
for(ff=primerPunto;ff<=cifras;ff+=3){
g+=enteros.substring(anterior,ff)+".";
anterior=ff;
}
pepe=g.substring(0,g.length-1)+","+decimales;
f['total_pvd'].value=pepe;
}
</script>
</head>
<body>
<form name="f1">
<input class="texto" type="Text" value="1.100.123,12" name="pvd_batlarga"><br />
<input class="texto" type="Text" value="123.000,23" name="pvd_funda"><br />
<input class="texto" type="Text" value="1.000,22" name="pvd_protector"><br />
================ <input type="button" value="sumar" onclick="sumar()"><br />
<input class="texto" type="Text" name="total_pvd"><br />
</form>
</body>
</html>
Un saludo!
__________________ Cómo escribir
No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia. |