Java Size sizeRenderer(String value)

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

Description

size Renderer

License

Open Source License

Declaration

public static String sizeRenderer(String value) 

Method Source Code

//package com.java2s;
/*/* w  w  w.  j  a  va  2 s. c  o  m*/
 * Copyright (C) 2012  Krawler Information Systems Pvt Ltd
 * All rights reserved.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; 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 sizeRenderer(String value) {
        Double size = Double.parseDouble(value);
        String text = "";
        Double val;
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        if (size >= 1 && size < 1024) {
            text = size + " Bytes";
        } else if (size > 1024 && size < 1048576) {
            val = (size / 1024);
            text = decimalFormat.format(val);
            text += " KB";
        } else if (size > 1048576) {
            val = (size / 1048576);
            text = decimalFormat.format(val);
            text += " MB";
        }
        return text;
    }
}

Related

  1. readableSize(long size)
  2. readableSize(long size, DecimalFormat format)
  3. renderNumber(int n, int size)
  4. size(long l)
  5. size2human(long size)
  6. stringToSize(String sizeString)
  7. toByte(String size)
  8. toHumanReadableSize(final long pSizeInBytes)
  9. toReadable(long size)