Created
February 10, 2014 12:58
-
-
Save vizhen/8915455 to your computer and use it in GitHub Desktop.
格式化文件大小
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 文件大小格式转换 | |
* @param fileS 文件大小 | |
* @return 文件大小 | |
*/ | |
public static String FormatFileSize(long fileS) | |
{ | |
// 转换文件大小 | |
DecimalFormat df = new DecimalFormat("#.00"); | |
String fileSizeString = ""; | |
if (fileS < 1024) | |
{ | |
fileSizeString = df.format((double) fileS) + "B"; | |
} | |
else if (fileS < 1048576) | |
{ | |
fileSizeString = df.format((double) fileS / 1024) + "KB"; | |
} | |
else if (fileS < 1073741824) | |
{ | |
fileSizeString = df.format((double) fileS / 1048576) + "MB"; | |
} | |
else | |
{ | |
fileSizeString = df.format((double) fileS / 1073741824) + "GB"; | |
} | |
return fileSizeString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment