javascript之取余数、去商、天花板取整、地板取整

demo1:

  console.log('//求余数');
  //求余数
  console.log(5 % 4);
  console.log(6 % 4);
  //求商
  console.log('//求商');
  console.log(1 / 4);
  console.log(6 / 4);
  //求商,取整
  console.log('//求商,取整');
  console.log(parseInt(1 / 4));
  console.log(parseInt(6 / 4));
  console.log('//求商,取小数');
  console.log(parseFloat(1 / 4));
  console.log(parseFloat(6 / 4));
  console.log(parseFloat(6 / 3));
  console.log('----');
  console.log('//天花板取整');
  //天花板取整
  console.log(Math.ceil(1 / 4));
  console.log('//地板取整');
  //地板取整
  console.log(Math.floor(3 / 4));

输出:

 

posted @ 2019-07-03 07:55  前端邢晋宇  阅读(2860)  评论(0编辑  收藏  举报