javascript对象之内置对象Math使用方法


一、Math.min()和Math.max(),分别返回参数中的最小和最大值
  例:
  alert(Math.min(1,2,3))  //输出 "1"
  alert(Math.max(1,2,3))  //输出 "3"

二、Math.abs(),返回参数的绝对值
  例:
  alert(Math.abs(-1))  //输出 "1"

三、Math.random(),产生一个0到1的随机数
  例:
  window.open("http://www.***.com/index.shtml?t="+Math.random)  //在url地址后面加上一个值为随即数的参数,能保证页面每次都从服务器上重新拉取,而不是读取缓存。

四、Math.floor(),Math.round(),Math.ceil()
  Math.floor():把小数向下舍入成整数    例:alert(Math.floor(1.5))  //输出"1"
  Math.round():把小数标准四舍五入成整数  例:alert(Math.round(1.5))  //输出"2"
  Math.ceil():把小数向上舍入成整数  例:alert(Math.round(1.5))  //输出"2"
  利用这三个函数,在涉及小数计算的时候就非常方便,比如设计如下函数来进行小数处理

  function test(num,flag,bit)  //参数分别是 要传入的小数"num"   舍入标准(-1,向下;0,标准;1向上)"flag"  保留小数的位数"bit"
  {
    var n=Math.pow(10,bit);
    switch(flag)
    {
      case -1:return Math.floor(num*n)/n;break;
      case 0:return Math.round(num*n)/n;break;
      case 1:return Math.ceil(num*n)/n;
    }
  }

javascript XMLHttpRequest对象全面剖析
一、引言异步JavaScript与XML(AJAX)是一个专用术语,用于实现在客户端脚本与服务器之间的数据交互过程。这一技术的优点在于,它向开发者提供了一种从W

JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解
首先还是看看JavaScript:TheDefinitiveGuide,4thEdition中对三个函数的定义。Math.ceil():roundanumberupArguments:AnynumericvalueorexpressionReturns:Theclosestintegergreaterthanorequaltox.--

js 小数取整的函数
1.丢弃小数部分,保留整数部分js:parseInt(7/2)2.向上取整,有小数就整数部分加1js:Math.ceil(7/2)3,四舍五入.js:Math.round(7/2)4,向下取整js:Math.floor(7/2)