class Formats {

    public static final String formatRate(double rate) {
        if (rate == 0) {
            return "    0";
        }
        else if (rate < 100) {
            return String.format("%5.2f", rate);
        }
        else if (rate < 1000) {
            return String.format("%5.1f", rate);
        }
        else if (rate < 100e3) {
            return String.format("%4.1fk", rate / 1e3);
        }
        else if (rate < 100e6) {
            return String.format("%4.1fm", rate / 1e6);
        }
        else if (rate < 100e9) {
            return String.format("%4.1fg", rate / 1e9);
        }
        else {
            return String.format("%5.1e", rate);
        }
    }

}