林凱立JavaSpript亂數random捨去小數floor進位ceil四捨五入round
343,344,345,346影片
財金程式設計343介紹物件object
財金程式設計344亂數RANDOM無條件捨去小數FLOOR
財金程式設計345乙班
財金程式設計346乙班RANDOM,FLOOR,CEIL,ROUND
輸入整數
The Math.random()亂數方法捨去小數Method方法
The Math.floor()捨去小數Method方法
The Math.ceil()進位Method方法
The Math.round()四捨五入Method方法
以上程式碼
輸入整數<input type="number" id ="n" value=10 min=1 max=1000 /><button onclick="abc()">林凱立執行</button>
<h3>The Math.random()亂數方法捨去小數Method方法</h3><p id="demo"></p>
<h3>The Math.floor()捨去小數Method方法</h3><p id="demo1"></p>
<h3>The Math.ceil()進位Method方法</h3><p id="demo2"></p>
<h3>The Math.round()四捨五入Method方法</h3><p id="demo3"></p>
<script>
function abc(){
let n = document.getElementById("n").value;
let x = Math.random()*n;
document.getElementById("demo").innerHTML = x;
document.getElementById("demo1").innerHTML = Math.floor(x);
document.getElementById("demo2").innerHTML = Math.ceil(x);
document.getElementById("demo3").innerHTML = Math.round(x);}
</script>
留言