Java Number Convert convertBytesToKBytes(String value)

Here you can find the source of convertBytesToKBytes(String value)

Description

convert Bytes to KiloBytes

License

Open Source License

Parameter

Parameter Description
value a parameter

Declaration

public static Long convertBytesToKBytes(String value) 

Method Source Code


//package com.java2s;
import java.math.BigDecimal;

import java.math.RoundingMode;

public class Main {
    private static final String KILOBYTECONVERTERVALUE = "1024";

    /**//w  w  w.jav a2s. c o  m
     * convert Bytes to KiloBytes
     * 
     * @param value
     * @return
     */
    public static Long convertBytesToKBytes(String value) {
        if (null == value) {
            return 0L;
        }
        BigDecimal val = new BigDecimal(value);
        BigDecimal kbconverter = new BigDecimal(KILOBYTECONVERTERVALUE);
        BigDecimal result = val.divide(kbconverter, RoundingMode.CEILING);
        // if the passed in Value from Provider is less than 1024 bytes, then by
        // default make it to 1 KB.
        if (result.longValue() == 0) {
            return 1L;
        }
        return result.longValue();
    }
}

Related

  1. convert(long value, long factor, int comma)
  2. convertBytesToUnit(long bytes)
  3. convertCount(Object obj)
  4. convertDurationToMillis(String time)
  5. convertedFileSize(Long fileSize)