分割字节流为G,MB,KB的算法
String HumanReadableFilesize(double size)
{
var units = new[] { "B", "KB", "MB", "GB", "TB", "PB" };
double mod = 1024.0;
var DoubleCount = new List<double>();
while (size >= mod)
{
size /= mod;
DoubleCount.Add(size);
}
var Ret = "";
for (int j = DoubleCount.Count; j > ; j--)
{
if (j == DoubleCount.Count)
{
Ret += $"{Math.Floor(DoubleCount[j - 1])}{units[j]}";
}
else
{
Ret += $"{Math.Floor(DoubleCount[j - 1] - (Math.Floor(DoubleCount[j]) * 1024))}{units[j]}";
}
}
return Ret;
}
将字节流大小转换成类似于XXGBXXMBXXKB的形式
分割字节流为G,MB,KB的算法的更多相关文章
- Applese 的毒气炸弹 G 牛客寒假算法基础集训营4(图论+最小生成树)
链接:https://ac.nowcoder.com/acm/contest/330/G来源:牛客网 Applese 的毒气炸弹 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262 ...
- java 上传文件大小转换为 GB/MB/KB/B
1.工具类 package cn.cmodes.common.utils; import java.io.File; import java.io.FileInputStream; import ja ...
- php文件大小单位转换GB MB KB
private function formatBytes($size){ $units = array('字节','K','M','G','T'); $i = 0; for( ; $size>= ...
- Problem G: 零起点学算法106——首字母变大写
#include<stdio.h> #include<string.h> int main(void) { ]; int i,k; while(gets(a)!=NULL) { ...
- Problem G: 零起点学算法102——删除字符
#include<stdio.h> #include<string.h> int main() { ],a; while(gets(ch)!=NULL) { scanf(&qu ...
- Problem G: 零起点学算法86——Fibonacc
#include<stdio.h> int main(){ ]={,,}; ;i<=;i++) { a[i]=a[i-]+a[i-]; } scanf("%d", ...
- Problem G: 零起点学算法27——等级分制度
#include<stdio.h> int main() { int a,b; while(scanf("%d %d",&a,&b)!=EOF) +a* ...
- GB MB KB B 关系
1KB=1024Bytes=2的10次方Bytes 1MB=1024KB=2的20次方Bytes 1GB=1024MB=2的30次方Bytes 1TB=1024GB=2的40次方Bytes
- 文件大小转换成可显示的Mb,Gb和kb方法
public static String unitConversion(float resource) { String[] unit = new String[] { "B", ...
随机推荐
- window下安装 node ,并搭建 vue 项目
uname -a 命令查看到我的Linux系统位数是64位(备注:x86_64表示64位系统, i686 i386表示32位系统) window下安装node 1.在官网上选择对应的位数的msi安装 ...
- java 文件目录树
1. 目标格式,使用tree命令时,目录树格式如下. public class TreeTest { public static void main(String[] args) { File roo ...
- selenium截图
文件结构 1.DateUtil.py # cncoding = utf-8 import time from datetime import datetime ''' 本文件主要用于获取当前的日期以及 ...
- 注册中心(Eureka)
1. pom.xml依赖 <dependencies> <dependency> <groupId>org.springframework.cloud</gr ...
- [原创]Modelsim后仿真
因调试需要,进行后仿真,ISE生成的sim文件和sdf文件 `timescale ns/ ps module lut_dly ( clkout, fpga_clk, config_in ); outp ...
- solution for python can not import local module
blog 这次遇到的问题是sys.path的输出不包含'',导致无法import当前文件和文件夹 When no ._pth file is found, this is how sys.path i ...
- Android Studio编译卡死
首先,用AS,你必须fanqiang,其它都是次要的. AS/bin/*.exe.vmoptions ## *DO NOT* modify this file directly. If there i ...
- C# 调用继电器api usb_relay_device.dll
C# 调用继电器api usb_relay_device.dll 代码封装 usb_relay_device.dll 为C++编写 using System; using System.Collect ...
- EF|CodeFirst数据并发管理
在项目开发中,我们有时需要对数据并发请求进行处理.举个简单的例子,比如接单系统中,AB两个客服同时请求处理同一单时,应该只有一单请求是处理成功的,另外一单应当提示客服,此单已经被处理了,不需要再处理. ...
- react-native项目中禁止截屏与录屏
在android/app/src/main/java/com/projname/MainActivity.java文件中的onCreate方法添加一下代码即可 import android.view. ...