js计算流量值的方法

来源:互联网 发布:python csvkit 编辑:程序博客网 时间:2024/04/28 04:51
//计算流量值( flowVlueBytes为流量的bytes字节数)
function getFlow(flowVlueBytes){
    var flow = "";
    //如果赠送流量小于1MB.则显示为KB
    if(flowVlueBytes/1024 < 1024){
        flow = (Math.round(flowVlueBytes/1024) > 0 ? Math.round(flowVlueBytes/1024) : 0) + 'KB';
    }else if(flowVlueBytes/1024 >= 1024 && flowVlueBytes/1024/1024 < 1024){
        //如果赠送流量大于1MB且小于1    GB的则显示为MB
        flow = (Math.round(flowVlueBytes/1024/1024) > 0 ? Math.round(flowVlueBytes/1024/1024) : 0)+'MB';
    }else if(flowVlueBytes/1024/1024 >= 1024){
        //如果流量大于1Gb
        var gb_Flow = flowVlueBytes/1024/1024/1024;
        //toFixed(1);四舍五入保留一位小数
        flow = gb_Flow.toFixed(1)+'GB';
    }else{
        flow = "0KB";
    }
    return flow;
}
0 0
原创粉丝点击