Java Number Format formatSmallerNumber(String prefix, String suffix, long amnt, boolean useDecimals)

Here you can find the source of formatSmallerNumber(String prefix, String suffix, long amnt, boolean useDecimals)

Description

format Smaller Number

License

Open Source License

Declaration

private static String formatSmallerNumber(String prefix, String suffix,
            long amnt, boolean useDecimals) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static String formatSmallerNumber(String prefix, String suffix,
            long amnt, boolean useDecimals) {
        switch (Long.toString(amnt).length()) {
        case 4:/*from   ww w. j a va  2 s  .c o m*/
            prefix += Long.toString(amnt).substring(0, 1)
                    + (useDecimals ? "."
                            + Long.toString(amnt).substring(1, 3) : "")
                    + "K" + suffix;
            return prefix;
        case 5:
            prefix += Long.toString(amnt).substring(0, 2)
                    + (useDecimals ? "."
                            + Long.toString(amnt).substring(2, 4) : "")
                    + "K" + suffix;
            return prefix;
        case 6:
            prefix += Long.toString(amnt).substring(0, 3)
                    + (useDecimals ? "."
                            + Long.toString(amnt).substring(3, 5) : "")
                    + "K" + suffix;
            return prefix;
        }
        return "";
    }
}

Related

  1. formatPhoneNumber(String phoneNumber)
  2. formatPrintIntegerToString(long number, boolean printCommasP, boolean printSignP, int radix, int mincol, char padchar, char commachar, int commainterval)
  3. formatRowKey(final long number, final int digits, byte[] dest)
  4. formatSafetyNumber(String digits)
  5. formatSheetNumber100(final int sheetNumber)
  6. formatTo2Digit(int number)
  7. NumberFormat(double str, int max, int min)
  8. numberFormat(double value, String format)
  9. numberFormat(int fractionDigits, Locale locale)