?? formatutilities.java
字號:
package de.uni_bremen.informatik.p2p.plugins.filesharing.control;
import java.text.NumberFormat;
/**
* Class contains methods for formating numbers and strings.
*
* @author Lars Kordes
*/
public class FormatUtilities {
/**
* Returns a formated String of a long integer.
*
* @param d Number the gets formated.
* @return String that contains the formated number.
*/
public static String giveFormatedString(long l) {
return Long.toString(l);
}
/**
* Gets file size and returns a correct formatted string.
*
* @param size File size
* @return Formatted string with file size in
*/
public static String giveCorrectSizeString(long size) {
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(1);
nf.setMinimumFractionDigits(1);
nf.setGroupingUsed(true);
// if size is less then one kbyte, return 1
if(size < 1024) return size + " B";
// if size is less then one Mbyte, return kbyte size
if(size < 1048576) return nf.format(size / 1024.0) + " KB";
// if return Mbyte size
if(size < 1073741824) return nf.format(size / (1024.0*1024.0)) + " MB";
// else gigabyte
else return nf.format(size / (1024.0*1024.0*1024.0)) + " GB";
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -