import java.text.DecimalFormat; public class SizeUtil { public static String GetImageSize(String imageSize) { String size = ""; if (imageSize != null && !"".equals(imageSize)) { long fileS = Long.parseLong(imageSize); DecimalFormat df = new DecimalFormat("#.00"); if (fileS < 1024) { size = df.format((double) fileS) + "BT"; } else if (fileS < 1048576) { size = df.format((double) fileS / 1024) + "KB"; } else if (fileS < 1073741824) { size = df.format((double) fileS / 1048576) + "MB"; } else { size = df.format((double) fileS / 1073741824) + "GB"; } } else { size = "0BT"; } return size; } }
字符串转成KB,MB, GB
猜你喜欢
转载自www.cnblogs.com/shix0909/p/11365074.html
今日推荐
周排行