List of utility methods to do Number Format
String | formatNumber(int number) insert commas to the given number for the readability StringBuilder s = new StringBuilder(); String intValue = Integer.toString(number); final int len = intValue.length(); for (int i = 0; i < len; ++i) { s.append(intValue.charAt(i)); int digit = len - i - 1; if (digit != 0 && (digit % 3 == 0)) { s.append(','); ... |
String | formatNumber(int number, int zeros) format Number String strZeros = repeatString("0", zeros); String strNumber = Integer.toString(number); return new StringBuilder().append(strZeros.substring(0, zeros - strNumber.length())).append(strNumber) .toString(); |
String | formatNumber(int theNumber, int theNumberOfDigits) format Number StringBuffer s = new StringBuffer(Integer.toString(theNumber)); while (s.length() < theNumberOfDigits) { s.insert(0, '0'); return s.toString(); |
String | formatNumber(int value, int width, char c) format Number String str = String.valueOf(value); if (str.length() > width) str = str.substring(0, width); return leftPad(str, width, c); |
Integer[] | formatNumber(Integer i, int bisectNumber) format Number Integer[] array = new Integer[bisectNumber]; Double doubleValue = i.doubleValue(); Double a = doubleValue / bisectNumber; Integer intValue = a.intValue(); for (int index = 0; index < bisectNumber; index++) { if (index != (bisectNumber - 1)) { array[index] = intValue; } else { ... |
String | FormatNumber(Integer pNumber, int tolLen) Format Number if (pNumber == null) pNumber = new Integer(0); String retVal = pNumber.toString(); for (int i = 0; i < tolLen - pNumber.toString().length(); i++) { retVal = " " + retVal; return retVal; |
String | formatNumber(long i, int digits) format Number return formatNumberImpl(i, digits, "0"); |
String | formatNumber(long number) format Number if (number >= 1000000000) { return ((number / 1000000000) + "B"); } else if (number >= 1000000) { return ((number / 1000000) + "M"); } else if (number >= 1000) { return ((number / 1000) + "K"); } else { return (number + ""); ... |
String | formatNumber(long number, int digits) format Number return formatNumber(number, digits, '0'); |
String | formatNumber(long pNum, int pLen) Formats a number with leading zeroes, to a specified length. StringBuilder result = new StringBuilder(); if (pNum >= Math.pow(10, pLen)) { throw new IllegalArgumentException( "The number to format cannot contain more digits than the length argument specifies!"); for (int i = pLen; i > 1; i--) { if (pNum < Math.pow(10, i - 1)) { result.append('0'); ... |