zoukankan      html  css  js  c++  java
  • Math.log()对数的妙用

     

    ###对数log 的妙用。。。

     

     

     formatBytes(bytes) {

            if (bytes === '0' || isNaN(bytes)) return '';

            var s = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];

            var e = Math.floor(Math.log(bytes) / Math.log(1024));

            return (bytes / Math.pow(1024, Math.floor(e))).toFixed(1) + " " + s[e];

        },

     

     

    function formatBytes(nums) {
    if (nums === '0' || isNaN(nums)) return '';
    var s = ['s', 'm', 'H'];
    var e = Math.floor(Math.log(nums) / Math.log(60));
    return (nums / Math.pow(60, Math.floor(e))).toFixed(1) + ' ' + s[e];
    }

    总结: 存在规律的进制转换的情况,比如  mb和byte都是1024 ;比如s秒和m分 都是60 。

  • 相关阅读:
    菜单无限极分类核心代码
    获取页面中更新删除传过来的id
    CI循环数组问题
    ci框架model中的进行增删改的写法
    MySQL DBA的修炼与未来(参考篇)
    Linux学习笔记(13)linux软件安装rpm与yum--理论篇
    Linux学习笔记(12)linux文件目录与用户管理
    Linux学习笔记(11)linux网络管理与配置之一——配置路由与默认网关,双网卡绑定(5-6)
    Linux学习笔记(10)linux网络管理与配置之一——主机名与IP地址,DNS解析与本地hosts解析(1-4)
    自定义流水号,前置加0
  • 原文地址:https://www.cnblogs.com/softwarelanguagebs/p/10758723.html
Copyright © 2011-2022 走看看