formatutilities.java
来自「peeranha42是jxta的 p2p程序核心」· Java 代码 · 共 43 行
JAVA
43 行
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";
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?