美文网首页
Math.floor

Math.floor

作者: 言笑笑 | 来源:发表于2017-01-22 09:55 被阅读0次

    Math.floor,
    求一个浮点数的地板,就是求一个最接近它的整数,它的值小于或等于这个浮点数
    document.write(Math.floor(0.6) =0
    document.write(Math.floor(1.40) =1

    在倒计时中time为剩余时间(单位:秒)
    function remains(time){
    var result = {};
    result.hour = Math.floor(time/3600); //小时
    time -= result.hour3600; //减去小时,剩下分钟和秒的时间
    result.minute = Math.floor(time/60); //分钟
    time -= result.minute
    60; //减去分钟,剩下秒
    result.second = Math.floor(time); //秒

    result.hour = pad(result.hour,2);     
    result.minute = pad(result.minute,2);
    result.second = pad(result.second,2);
    return result
    

    }

    相关文章

      网友评论

          本文标题:Math.floor

          本文链接:https://www.haomeiwen.com/subject/shanbttx.html