1
<p id="demo">单击按钮显示保留小数的数值</p>
2
<button onclick="myFunction()">点我</button>
3
<script>
4
function myFunction() {
5
var num = 5.56789;
6
var x = document.getElementById("demo");
7
x.innerHTML = num.toFixed(2);
8
}
9
</script>
<p id="demo">单击按钮显示保留小数的数值</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction() {
var num = 5.56789;
var x = document.getElementById("demo");
x.innerHTML = num.toFixed(2);
}
</script>