js 四舍五入取整数

阅读 161

2022-07-27


一、四舍五入取整数 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

精彩评论(0)

0 0 举报