hal/src/zutil/StringUtil.java

31 lines
608 B
Java
Raw Normal View History

2008-11-14 16:38:36 +00:00
package zutil;
/**
* This is a class whit utility methods.
*
* @author Ziver *
*/
public class StringUtil {
/**
* Present a size (in bytes) as a human-readable value
*
* @param size size (in bytes)
* @return string
*/
public static String formatBytesToString(long bytes){
String[] sizes = new String[]{"YB", "ZB", "EB", "PB", "TB", "GB", "MB", "kB", "B"};
int total = sizes.length-1;
double value = bytes;
for(; value > 1024 ;total--) {
value /= 1024;
}
value = (double)( (int)(value*100) )/100;
return value+" "+sizes[total];
}
}