Java Long Number Readable Format convertMbIntoGb(long megaBytes)

Here you can find the source of convertMbIntoGb(long megaBytes)

Description

convert Mb Into Gb

License

Open Source License

Declaration

public static String convertMbIntoGb(long megaBytes) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * ===========================================================
 * Ankush : Big Data Cluster Management Solution
 * ===========================================================
 * //from w w  w .j  a  va  2  s .c o  m
 * (C) Copyright 2014, by Impetus Technologies
 * 
 * This is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License (LGPL v3) as
 * published by the Free Software Foundation;
 * 
 * This software is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this software; if not, write to the Free Software Foundation, 
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ******************************************************************************/

import java.text.DecimalFormat;

public class Main {
    public static String convertMbIntoGb(long megaBytes) {
        String convertedVal = "0";
        if (megaBytes == 0) {
            return convertedVal;
        }

        final double HUNDRED = 100.0;
        final long DIVEDEBY = 1024L;

        DecimalFormat df = new DecimalFormat("0.00");

        if (megaBytes / DIVEDEBY > 0) {
            return (df.format(((megaBytes * HUNDRED / DIVEDEBY)) / HUNDRED) + "GB");
        } else {
            return (String.valueOf(megaBytes) + "MB");
        }
    }
}

Related

  1. convertBytes(long size)
  2. convertByteToGMKB(long bytes)
  3. convertByteUnit(Long l)
  4. convertHumanSize(long byteSize)
  5. convertLongToMega(long value)
  6. formatBytes(long bts)
  7. formatBytes(long bytes)
  8. formatBytes(long bytes)
  9. formatBytes(long bytes)