js 四捨五入取整數

一、四捨五入取整數 Math.round()

console.log(Math.round(2.5));//3

console.log(Math.round(2.4));//2

<script>
function myFunction(){
	document.getElementById("demo").innerHTML=Math.round(2.5);
}
</script>

結果:3

 

二、取整數部分,不四捨五入 parseInt()

$("#order_total").html(parseInt(total));

console.log(parseInt(2.5));//2

console.log(parseInt(2.4));//2

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章