Java Utililty Methods Number Format

List of utility methods to do Number Format

Description

The list of methods to do Number Format are organized into topic(s).

Method

StringformatCCNumber(String f, String s)
format CC Number
if (s == null || s.length() < 15) {
    throw new IllegalArgumentException("[" + s + "]");
String format = f;
String formatted;
if (s.length() == 16) {
    if (format == null || format.length() == 0) {
        format = "%.4s %.4s %.4s %.4s";
...
StringformatCsv(final Number number)
format Csv
if (number == null) {
    return "";
return formatCsv(number.longValue());
ObjectformatFolioNumber(Integer folioNum, String folioMod)
This method will format an input id for document identifier.
String value = "00" + folioNum.toString();
return value.substring(value.length() - 3);
StringformatFromCurrentPageIndex(int nbItemsPerPage, int totalNumberOfItems, int indexOfCurrentPage)
Centralizes the formatting of a pagination context label.
return formatFromFirstIndexOfItem(nbItemsPerPage, totalNumberOfItems,
        (nbItemsPerPage * indexOfCurrentPage));
intformatInt(String number)
format Int
try {
    return new Integer(number);
} catch (Exception e) {
return -1;
StringFormatIntNoWithZero(int pNumber, int tolLen)
Format Int No With Zero
Integer pNo = new Integer(pNumber);
String retVal = pNo.toString();
for (int i = 0; i < tolLen - pNo.toString().length(); i++) {
    retVal = "0" + retVal;
return retVal;
StringformatLineNumber(String lineNumber)
format Line Number
return (lineNumber != null) ? (lineNumber + " ") : "";
StringformatMs(long number)
format Ms
long hrs = number / HRS;
number = number % HRS;
long mins = number / MINS;
number = number % MINS;
long secs = number / SECS;
return (hrs > 0 ? hrs + "hours " : "") + (mins > 0 ? mins + " minutes " : "")
        + (mins < 2 ? secs + " seconds" : "");
StringformatNationalNumber(String nationalNumber)
format National Number
StringBuilder formatted = new StringBuilder(nationalNumber.substring(0, 2));
formatted.append('.');
formatted.append(nationalNumber.substring(2, 4));
formatted.append('.');
formatted.append(nationalNumber.substring(4, 6));
formatted.append('-');
formatted.append(nationalNumber.substring(6, 9));
formatted.append('.');
...
StringformatNCPDPNumber(String origNumber, int decimalPoints)
format NCPDP Number
if (origNumber == null || origNumber.equals("")) {
    return "";
if (origNumber.endsWith("{")) {
    origNumber = origNumber.replace("{", "0");
} else if (origNumber.endsWith("A")) {
    origNumber = origNumber.replace("A", "1");
} else if (origNumber.endsWith("B")) {
...