Java Number Format formatCsv(final Number number)

Here you can find the source of formatCsv(final Number number)

Description

format Csv

License

Apache License

Declaration

public static String formatCsv(final Number number) 

Method Source Code

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

public class Main {
    public static String formatCsv(final Number number) {
        if (number == null) {
            return "";
        }//from   w  w  w  .  j a va  2s .  com
        return formatCsv(number.longValue());

    }

    public static String formatCsv(final Long number) {
        if (number == null) {
            return "";
        }
        final String s = String.valueOf(number);
        final StringBuilder sb = new StringBuilder();

        for (int i = 0; i < s.length(); i++) {
            if ((s.length() - i) % 3 == 0) {
                if (sb.length() > 0) {
                    sb.append(",");
                }
            }
            sb.append(s.charAt(i));
        }
        return sb.toString();
    }
}

Related

  1. formatBinaryNumber(int number, int size)
  2. formatBytes(long number)
  3. formatBytesHumanReadable(float number)
  4. formatCardNumber(String cardNumber)
  5. formatCCNumber(String f, String s)
  6. formatFolioNumber(Integer folioNum, String folioMod)
  7. formatFromCurrentPageIndex(int nbItemsPerPage, int totalNumberOfItems, int indexOfCurrentPage)
  8. formatInt(String number)
  9. FormatIntNoWithZero(int pNumber, int tolLen)