當前位置:文思屋>社會工作>電腦培訓>

JavaScript中用於四捨五入的Math.round方法講解

文思屋 人氣:2.9W

此方法返回一個數四捨五入為最接近的整數的`值。

JavaScript中用於四捨五入的Math.round方法講解

語法

d( x ) ;

下面是引數的詳細資訊:

x: 一個數字

返回值:

返回數字四捨五入為最接近的整數的值。

例子:

JavaScript Math round() Method

這將產生以下結果:

First Test Value : 1Second Test Value : 21Third Test Value : 20Fourth Test Value : -20