source: java/installer2/src/net/oni2/aeinstaller/backend/SizeFormatter.java@ 730

Last change on this file since 730 was 594, checked in by alloc, 12 years ago

AEI2: .NET detection

File size: 845 bytes
Line 
1package net.oni2.aeinstaller.backend;
2
3/**
4 * @author Christian Illy
5 */
6public class SizeFormatter {
7 /**
8 * @param sizeVal
9 * Size in Byte
10 * @param digits
11 * Number of digits
12 * @return Formatted value
13 */
14 public static String format(long sizeVal, int digits) {
15 String names[] = { "B", "KiB", "MiB", "GiB" };
16 int nameInd = 0;
17 float size = sizeVal;
18 while (size > 1024) {
19 nameInd++;
20 size /= 1024;
21 }
22 if (size < 10)
23 return String.format(
24 "%1." + String.valueOf(Math.max(digits - 1, 0)) + "f %s",
25 size, names[nameInd]);
26 else if (size < 100)
27 return String.format(
28 "%1." + String.valueOf(Math.max(digits - 2, 0)) + "f %s",
29 size, names[nameInd]);
30 else
31 return String.format(
32 "%1." + String.valueOf(Math.max(digits - 3, 0)) + "f %s",
33 size, names[nameInd]);
34 }
35}
Note: See TracBrowser for help on using the repository browser.