0
点赞
收藏
分享

微信扫一扫

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

举报

相关推荐

0 条评论