Java Number Convert convertedFileSize(Long fileSize)

Here you can find the source of convertedFileSize(Long fileSize)

Description

converted File Size

License

Open Source License

Declaration

public static String convertedFileSize(Long fileSize) 

Method Source Code

//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;
    }
}

Related

  1. convert(long value, long factor, int comma)
  2. convertBytesToKBytes(String value)
  3. convertBytesToUnit(long bytes)
  4. convertCount(Object obj)
  5. convertDurationToMillis(String time)
  6. convertFromMsToMinutes(Integer duration)
  7. convertGeoCoordinateToDouble(int point)
  8. convertImperialToMetric(String areaImp)
  9. convertJcoDecimalDefaultValue( String jcoDefaultDecimalValue)