ITeye博客

js 保留n为小数

jarod2008 · 2009-03-31 18:07 · 静态语言 · prototype · Markdown

Number.prototype.toFixed=function(len)//精确小数  
  {  
  if(isNaN(len)||len==null)  
  {  
  len   =   0;  
  }  
  else  
  {  
  if(len<0)  
  {  
  len   =   0;  
  }  
  }  
  return   Math.round(this   *   Math.pow(10,len))   /   Math.pow(10,len);  
  }  
   
    var   t=parseFloat(form1.text2.value)*parseFloat(form1.text3.value);  
    form1.text1.value=t.toFixed(2)

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。