方法1:

<script type="text/javascript">

   var a=2.1512131231231321;

   document.write("原来的值:"+a+"<br>");

   document.write("两位小数点:"+a.toFixed(2)+"<br>四位小数点"+a.toFixed(4));

</script>

方法2:

<script type="text/javascript">

    function turn(val){
        var size = new Number(val);
        return size.toFixed(2);
    }
</script>