I want to use this code to convert bytes into proper values
import java.util.*;
import java.lang.*;
import java.io.*;
import java.text.DecimalFormat;
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
String readableFileSize = readableFileSize(9394343298L);
System.out.println("Result " + readableFileSize);
}
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(1024));
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
}
The lode works but I have to place L after the number. In my case I use closed source library which when I use it I can't add L. Is there any way to refactor to code to convert very big values into proper format?