Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

public class Main {
    public static String FormetFileSize(long fileSize) {
        DecimalFormat df = new DecimalFormat("0.0");
        String fileSizeString = "";
        if (fileSize < 1024L)
            fileSizeString = df.format(fileSize) + "B";
        else if (fileSize < 1048576L)
            fileSizeString = df.format(fileSize / 1024.0D) + "K";
        else if (fileSize < 1073741824L)
            fileSizeString = df.format(fileSize / 1048576.0D) + "M";
        else {
            fileSizeString = df.format(fileSize / 1073741824.0D) + "G";
        }
        return fileSizeString;
    }
}