Javascript--Boolean/Math

Boolean描述:

创建新的 Boolean 值

var boolObj = new Boolean([boolValue])

如果忽略 Boolvalue ,或者其值为 false、0、nullNaN,或者空字符串,则该 Boolean 对象的初始值为 false。否则,初始值为 true

Boolean方法:

方法 描述 备注
toString() 将逻辑值转化为字符串,并返回  
valueOf() 返回boolean值的原始值  

 

 

Math描述:

提供基本数学函数和常数

Math属性:

属性 描述 备注
E 常量 e,自然对数的底数 约等于2.718
LN2 返回 2 的自然对数 约等于0.693
LN10 返回 10 的自然对数 约等于2.302
LOG2E 返回以 2 为底的 e 的对数 约等于 1.414
LOG10E 返回以 10 为底的 e 的对数 约等于0.434
PI 返回圆周率 约等于3.14159
SQRT1_2 返回 2 的平方根分之一 约等于 0.707
SQRT2 返回 2 的平方根 约等于 1.414

Math方法:

方法 描述 备注
abs(x) 返回数的绝对值  
sin(x) 返回数(弧度)的正弦值  
cos(x) 返回数(弧度)的余弦值  
asin(x) 返回数的反正弦值  
acos(x) 返回数的反余弦值  
tan(x) 返回数(弧度)的正切值  
atan(x) 以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值  
atan(x,y) 返回从 x 轴到点 (x,y) 的角度(介于 -PI/2 与 PI/2 弧度之间)  
max(x,y) 返回x,y中最大的数字  
min(x,y) 返回x,y中最小的数字  
pow(x,y) 返回x的y次幂  
sqrt(x) 返回数的平方根  
ceil(x) 对一个数进行向上舍入,返回一个整数  
floor(x) 对一个数进行向下舍入,返回一个整数  
round(x) 把一个数四舍五入为最近的整数  
exp(x) 返回e的指数  
log(x) 返回数的自然对数(底数为e)  
random() 返回0--1之间的随机数  

 

Math例子:

    <script type="text/javascript">
        document.write("<br/>Math.abs(-1):"+Math.abs(-1));
        document.write("<br/>Math.sin(Math.PI/6):"+Math.sin(Math.PI/6));
        document.write("<br/>Math.cos(Math.PI/3):"+Math.cos(Math.PI/3));
        document.write("<br/>Math.asin(0.5)*180/Math.PI:"+Math.asin(0.5)*180/Math.PI);
        document.write("<br/>Math.acos(0.5)*180/Math.PI:"+Math.acos(0.5)*180/Math.PI);
        document.write("<br/>Math.tan(Math.PI/3):"+Math.tan(45*Math.PI/180));
        document.write("<br/>Math.atan(1)*180/Math.PI:"+Math.atan(1)*180/Math.PI);
        document.write("<br/>Math.max(9,10):"+Math.max(9,10));
        document.write("<br/>Math.min(9,10):"+Math.min(9,10));
        document.write("<br/>Math.pow(2,3):"+Math.pow(2,3));
        document.write("<br/>Math.sqrt(9):"+Math.sqrt(9));
        document.write("<br/>Math.ceil(9.1):"+Math.ceil(9.1));
        document.write("<br/>Math.floor(9.1):"+Math.floor(9.1));
        document.write("<br/>Math.round(9.31):"+Math.round(9.31));
        document.write("<br/>Math.round(9.7):"+Math.round(9.7));
        document.write("<br/>Math.exp(2):"+Math.exp(1));
        document.write("<br/>Math.log(2):"+Math.log(1));        
        document.write("<br/>Math.random:"+Math.random());
    </script>
结果:
image 
posted @ 2009-06-01 09:24  Localhost  阅读(340)  评论(0编辑  收藏  举报