码迷,mamicode.com
首页 > Web开发 > 详细

JS Math.max() 函数

时间:2014-11-10 11:30:31      阅读:1146      评论:0      收藏:0      [点我收藏+]

标签:style   color   ar   sp   for   on   bs   ad   ef   

 

Math.max(a,b,...,x,y) -- 返回数个数字中较大的值 
max是maximum的缩写,中文"最大量"的意思

 

 

max函数语法
Math.max(a,b,...,x,y);


max函数参数
a,b,...,x,y -- 为number类型的数字,可以是小数、整数;正数、负数、0.


max函数返回值
返回数个数值中较大的值

 

注:如果max函数没有给出任何参数,返回-Infinity

如果有NaN或者非数字类型的参数,返回NaN

max函数示例
document.write(Math.max(5,8,6,-5,-6));
document.write(Math.max());
document.write(Math.max("dreamdu",8));
document.write(Math.max(NaN,0));
结果:

8
-Infinity
NaN
NaN

 

----------------------------------------------------------------------------------

Math其他相关函数:
Math.random()
返回 0 ~ 1 之间的随机数。


Math.round()
四舍五入取整。


Math.ceil()
返回值:返回大于或等于x,并且与之最接近的整数。
注:如果x是正数,则把小数“入”;如果x是负数,则把小数“舍”。


Math.floor()
返回值:返回小于或等于x,并且与之最接近的整数。
注:如果x是正数,则把小数“舍”;如果x是负数,则把小数“入”。

JS Math.max() 函数

标签:style   color   ar   sp   for   on   bs   ad   ef   

原文地址:http://www.cnblogs.com/lvjianjishui/p/4086594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!