开发手册 欢迎您!
软件开发者资料库

JavaScript(JS) Math.round( x )

Math对象为数学常量和函数提供属性和方法。与其他全局对象不同,Math不是构造函数。Math的所有属性和方法都是静态的,可以通过将Math作为对象来调用,而无需创建它。本文主要介绍JavaScript(JS) Math.round( x ) 方法。

1、描述

返回一个数值四舍五入到最接近的整数。  

2、语法

它的语法如下:

Math.round( x )

3、返回值

返回舍入到最接近的整数的数字的值。

4、使用示例

            JavaScript Math round() Method                              var value = Math.round( 0.5 );         document.write("Math.round( 0.5 ) : " + value ); <br>                  var value = Math.round( 20.7 );         document.write("<br />Math.round( 20.7 ) : " + value ); <br>                  var value = Math.round( 20.3 );         document.write("<br />Math.round( 20.3 ) : " + value ); <br>                  var value = Math.round( -20.3 );         document.write("<br />Math.round( -20.3 ) : " + value ); <br>            

5、输出

Math.round( 0.5 ) : 1Math.round( 20.7 ) : 21Math.round( 20.3 ) : 20Math.round( -20.3 ) : -20