JS精确到小数点后N位

来源:互联网 发布:hbm显存 知乎 编辑:程序博客网 时间:2024/04/27 23:06

<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>