简单教程
提交运行
代码编辑器:
<p id="demo">单击按钮来显示格式化的数字</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var num = new Number(13.3714); var a = num.toPrecision(); var b = num.toPrecision(2); var c = num.toPrecision(3); var d = num.toPrecision(10); var n=a + "<br>" + b + "<br>" + c + "<br>" + d; var x = document.getElementById("demo"); x.innerHTML=n } </script>
运行结果: