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 。

  • 相关阅读:
    WPF数据绑定之4种绑定模式
    MVVM弹出提示
    MVVM 事件汇总
    C#读取数据库返回泛型集合 把DataSet类型转换为List泛型集合
    WINFORM 父窗体Load事件中打开子窗体并关闭自身
    常用正则表达式
    GridView密技#3GridView合并储存格后,隔列变底色(AlternatingRowStyle)
    自己动手写的版本 网站的 Detail程序 (DataReader)
    [入门] 双重关联 下拉式选单(DropDownList)
    GridView密技#2GridView合并储存格
  • 原文地址:https://www.cnblogs.com/softwarelanguagebs/p/10758723.html
Copyright © 2011-2022 走看看