zoukankan      html  css  js  c++  java
  • 面试题1

    1,math.round(11.5)=?   math.round(-11.5)=?,这个题其实特别简单,为什么当时就是给忘记了,主要的原因可能就是因为自己平时用的蛮少,因为平时怎么可能会经常用到四舍五入呢?

    math.round(x)这个方法表示就是将x四舍五入取整,它的源码是这样的:math.floor(x+0.5);所以math.round(11.5)=math.floor(11.5+0.5)=math.floor(12.0)=12<floor是向下取整>

    math.round(-11.5)=math.floor(-11.5+0.5)=math.floor(-11.0)=-11,<向下取整>

    除了这个math.round(x),这个函数以外还有几个类似的

    math.floor(x);  math.ceil(x);   math.rint(x);

    math.floor(x)是向下取整,也就是去x在数轴上接近下面的那个最近的整数floor(11.6)=11

    math.ceil(x)它跟floor是相反的,是去x在数轴上接近上面的那个最近的整数ceil(11.3)=12

    math.rint(x)它的话是去跟x最接近的那个整数,rint(11.8)=12;rint(11.2)=11

  • 相关阅读:
    Document
    Document
    Document
    2.原型和原型链的关系以及查找顺序
    1.面向对象 及 相关知识点
    时间对象 <-> 定时器 <-> 电子时钟 <-> 倒计时效果
    定时器
    let var const 的区别
    ES6 中块的概念
    js中的闭包
  • 原文地址:https://www.cnblogs.com/shiwanming/p/9891405.html
Copyright © 2011-2022 走看看