2014-04-04 49 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); 
相關問題