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 。

  • 相关阅读:
    Uva 10719 Quotient Polynomial
    UVa 11044 Searching for Nessy
    Uva 10790 How Many Points of Intersection?
    Uva 550 Multiplying by Rotation
    Uva 10916 Factstone Benchmark
    Uva 10177 (2/3/4)D Sqr/Rects/Cubes/Boxes?
    Uva 591 Box of Bricks
    Uva 621 Secret Research
    Uva 10499 The Land of Justice
    Uva 10014 Simple calculations
  • 原文地址:https://www.cnblogs.com/softwarelanguagebs/p/10758723.html
Copyright © 2011-2022 走看看