现在的位置: 首页 > 综合 > 正文

JS精确到小数点后N位

2012年01月18日 ⁄ 综合 ⁄ 共 213字 ⁄ 字号 评论关闭

<script language="JavaScript">

function round(v,e)  
  {  
    var   t=1;  
    e=Math.round(e);  
    for(;e>0;t*=10,e--);  
    for(;e<0;t/=10,e++);  
    return   Math.round(v*t)/t;  
  }
  

alert(round(12.3456,2));//12.35

</script>

抱歉!评论已关闭.