Java Number Format formatNumberFloorWithPostfix(int value)

Here you can find the source of formatNumberFloorWithPostfix(int value)

Description

Formats the number in value into a floored, postfixed form for display.

License

LGPL

Parameter

Parameter Description
value a parameter

Declaration

public static String formatNumberFloorWithPostfix(int value) 

Method Source Code

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

public class Main {
    /**//from  w  w  w.  ja v  a 2s.  c  o m
     * Formats the number in value into a floored, postfixed form for display.
     * Supported formats are: 0..1000, 1.0k..9.9k, 10k..999k, 1M..nM
     * @param value
     * @return
     */
    public static String formatNumberFloorWithPostfix(int value) {
        if (value >= 1000000000) {
            return String.format("%dG", value / 1000000000);
        }

        if (value >= 1000000) {
            return String.format("%dM", value / 1000000);
        }

        if (value >= 10000) {
            return String.format("%dk", value / 1000);
        }

        if (value > 1000) {
            return String.format("%.1fk", ((float) value) / 1000);
        }

        return String.valueOf(value);
    }
}

Related

  1. formatNumber(Object num)
  2. formatNumber(String formatStr, int length, boolean leftPadding, char paddingCharacter)
  3. formatNumber(String num, int n)
  4. formatNumber(String s, Character thousandsSeparator, Character decimalSeparator)
  5. formatNumber(String value)
  6. formatNumberImpl(long i, int digits, String fill)
  7. formatNumbers(final int... numbers)
  8. formatNumberWithExtension(int num)
  9. formatNumberWithKSeparators(int value)