有没有简单的方法来创建一个使用的类 IFormatProvider它写出一个用户友好的文件大小?
public static string GetFileSizeString(string filePath)
{
FileInfo info = new FileInfo(@"c:\windows\notepad.exe");
long size = info.Length;
string sizeString = size.ToString(FileSizeFormatProvider); // This is where the class does its magic...
}
Run Code Online (Sandbox Code Playgroud)
它应该导致字符串格式化为" 2,5 MB "," 3,9 GB "," 670字节 "等等.
如何用C#格式化SO这样的数字?
10,5k,......