JavaScript - evitar redondear decimales

 
Vista:

evitar redondear decimales

Publicado por deysi (11 intervenciones) el 13/11/2009 16:45:45
Hola tengo esta funcion pero me redondea las cantidades,
como evito que se redonden

hogala y alguien me pueda ayudar por favor

function formatoFlotante2(num,operacion)
{
if (operacion=="aplicar") //Aplica formato
{
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0"; alert("1: "+num)
cents = Math.floor((num*100+0.5)%100); alert("2: "+cents);
num = Math.floor((num*100+0.5)/100).toString(); alert("3: "+num);
if(cents < 10) cents = "0" + cents; alert("4: "+cents);
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) alert("4: "+num.length);
num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3)); alert("5: "+num);
return (num + "." + cents);
}
else //operacion="quitar" --> Quitar el formato
{
num = num.toString().replace(/\$|\,/g,'');
return num;
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder