Ver Mensaje Individual
  #3 (permalink)  
Antiguo 22/02/2006, 10:29
Davhira
 
Fecha de Ingreso: mayo-2005
Mensajes: 63
Antigüedad: 19 años
Puntos: 1
Prueba este codigo

<html>
<head>
<title>Untitled</title>
<script language="JavaScript">
function formato(cant)
{
var temp, temp1, temp2, strng, cifras, inic
if (cant<0)
{
inic='$-'
cant=cant*-1
}
else
{
inic='$'
}

strng=''
cifras=Math.round((cant-(Math.floor(cant)))*100)
cant=Math.floor(cant)

if (cifras<10)
{
cifras='0'+String(cifras)
}

while (cant>=1000)
{
temp=cant/1000
temp1=Math.floor(temp)
temp2=temp-temp1
cant=Math.floor(cant/1000)
temp2=Math.round(temp2*1000)
if (temp2<10)
{
temp2='0'+'0'+String(temp2)
}
else
{
if (temp2<100)
{
temp2='0'+String(temp2)
}
else
{
temp2=String(temp2)
}
}
strng=','+temp2+strng
}
strng=inic+cant+strng+'.'+cifras
document.formulario.cantidad.value=strng
}

</script>
</head>
<body>
<form name="formulario">
Cantidad:<input type="text" name="cantidad" size="12" maxlength="12" >
<input type="button" value="procesar" onclick="formato(cantidad.value)">
</form>
</body>
</html>