Here you can find the source of getSpaceSizeFromByte(long xB)
public static String getSpaceSizeFromByte(long xB)
//package com.java2s; /* Copyright 2007-2011 MTA SZTAKI LPDS, Budapest //from ww w .j a va2s.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import java.text.*; public class Main { public static String getSpaceSizeFromByte(long xB) { String ret = ""; DecimalFormat myFormatter = new DecimalFormat("###.###"); double xBd = (double) xB; long Hi = 1; Hi = Hi << 60; long Pi = 1; Pi = Pi << 50; double Pd = (double) Pi; long Ti = 1; Ti = Ti << 40; double Td = (double) Ti; long Gi = 1; Gi = Gi << 30; double Gd = (double) Gi; long Mi = 1; Mi = Mi << 20; double Md = (double) Mi; long Ki = 1; Ki = Ki << 10; double Kd = (double) Ki; if ((xB >= Hi) || (xB < 0)) ret = "unreliable high"; else if (xB >= Pi) { ret = myFormatter.format(xBd / Pd) + " [PB]"; } else if (xB >= Ti) { ret = myFormatter.format(xBd / Td) + " [TB]"; } else if (xB >= Gi) { ret = myFormatter.format(xBd / Gd) + " [GB]"; } else if (xB >= Mi) { ret = myFormatter.format(xBd / Md) + " [MB]"; } else if (xB >= Ki) { ret = myFormatter.format(xBd / Kd) + " [KB]"; } else ret = myFormatter.format(xB) + " [B]"; return ret; } }