Here you can find the source of formatDataSize(long bytes)
public static String formatDataSize(long bytes)
//package com.java2s; /*/*from ww w . j a va2s . c o m*/ * Copyright (C) 2007, 2008 Quadduc <quadduc@gmail.com> * Copyright (C) 2007, 2011 IsmAvatar <IsmAvatar@gmail.com> * Copyright (C) 2007 Clam <clamisgood@gmail.com> * Copyright (C) 2013, 2014 Robert B. Colton * * This file is part of LateralGM. * LateralGM is free software and comes with ABSOLUTELY NO WARRANTY. * See LICENSE for details. */ import java.text.DecimalFormat; public class Main { public static String formatDataSize(long bytes) { if (bytes <= 0) return "0 B"; final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; int digits = (int) (Math.log(bytes) / Math.log(1024)); return new DecimalFormat("#,##0.##").format(bytes / Math.pow(1024, digits)) + " " + units[digits]; } }