[Logo] JForum - Powering Communities
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


JForum 2.8.3 is out with various fixes and improvements. Read all about it here

Code test RSS feed
Forum Index » Test Me
Author Message
avec


Joined: 2014/2/22
Messages: 9
Offline

public class Format {

public static String numberFormat(int value) {
NumberFormat myFormatter = NumberFormat.getInstance();
return myFormatter.format(value);
}

public static String decimalFormat(String pattern, int value) {
DecimalFormat myFormatter = new DecimalFormat(pattern);
return myFormatter.format(value);
}

public static void main(String[] args) {
System.out.println(Format.readableFileSize(1000000));
}


public static String readableFileSize(long size) {
if (size <= 0) return "0";
final String[] units = new String[]{"B", "KB", "MB", "GB", "TB"};
int digitGroups = (int) (Math.log10(size) / Math.log10(1000));
return new DecimalFormat("#,##0.#").format(size / Math.pow(1000, digitGroups)) + " " + units[digitGroups];

}
}
avec


Joined: 2014/2/22
Messages: 9
Offline

var speedCheck = (function (start) {
var end = new Date().getTime();
var time = (end - start);
alert("Time(millisec) : " + time);
});
 
Forum Index » Test Me
Go to:   
Mobile view
Powered by JForum 2.8.3 © 2023 JForum Team • Maintained by Andowson Chang and Ulf Dittmer