Here you can find the source of convertedFileSize(Long fileSize)
public static String convertedFileSize(Long fileSize)
//package com.java2s; import java.math.BigDecimal; import java.math.RoundingMode; public class Main { public static String convertedFileSize(Long fileSize) { String convertedSize = null; //if1024*1024 1M if (fileSize >= 1024 * 1024) { convertedSize = BigDecimal.valueOf(fileSize).divide( BigDecimal.valueOf(1024 * 1024), 1, RoundingMode.HALF_UP) + "M"; } else if (fileSize >= 1024) { convertedSize = BigDecimal.valueOf(fileSize).divide( BigDecimal.valueOf(1024), 1, RoundingMode.HALF_UP) + "K"; } else {//from www . j av a 2 s .c om convertedSize = "1B"; } return convertedSize; } }