function tofloat(f,dec)
{
if(dec<0) return "Error:dec<0!";
result=parseInt(f)+(dec==0?"":".");
f-=parseInt(f);
if(f==0)
for(i=0;i<dec;i++)
result+='0';
else
{
for(i=0;i<dec;i++)
f*=10;
result+=parseInt(Math.round(f));
}
return result;
}
window.status=tofloat(11.20000000000000000001,3);
{
if(dec<0) return "Error:dec<0!";
result=parseInt(f)+(dec==0?"":".");
f-=parseInt(f);
if(f==0)
for(i=0;i<dec;i++)
result+='0';
else
{
for(i=0;i<dec;i++)
f*=10;
result+=parseInt(Math.round(f));
}
return result;
}
window.status=tofloat(11.20000000000000000001,3);
alert(a.toFixed(4))
alert(a.toFixed(2))
记得给分哦