2014-04-04 47 views
2

我想将130.68(大于或等于130.5)和131.32(小于131.5)的值舍入为131如何在Jquery中将浮点值四舍五入为最接近的整数

+2

[Math.round()](https://developer.mozilla.org/en-US/ docs/Web/JavaScript/Reference/Global_Objects/Math/round) – Satpal

+1

[如何将数字转换为Javascript中的整数?](http://stackoverflow.com/questions/596467/how-do-i -convert-a-number-to-an-integer-in-javascript) –

回答

2

你既需要声明下面使用Math.round(),在例如将提醒131

alert(Math.round(130.68)); 
alert(Math.round(131.32)); 

DEMO

1

您可以使用Math.round

num=130.68; 
Math.round(num); 
相关问题