Java Number Format Pattern formatInt(final int number)

Here you can find the source of formatInt(final int number)

Description

Format a 'int' number with default pattern

License

Creative Commons License

Parameter

Parameter Description
number a parameter

Return

contains the string representation.

Declaration

public static String formatInt(final int number) 

Method Source Code

//package com.java2s;
/**/*from   w  w w .  j a  v  a  2  s  .c om*/
 * Generic utility class.
 * <p/>
 * This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 United States License. To
 * view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/us/ or send a letter to Creative
 * Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
 *
 * @author $Author: jal55 $
 * @version $Rev: 8005 $
 * @package edu.psu.iam.cpr.core.util
 * @lastrevision $Date: 2013-09-11 08:47:10 -0400 (Wed, 11 Sep 2013) $
 */

import java.text.DecimalFormat;

public class Main {
    /**
     * Pattern for pretty-formatting an int/long
     */
    private static final String INTEGER_PATTERN = "###,###,###,##0";

    /**
     * Format a 'int' number with default pattern
     *
     * @param number
     * @return contains the string representation.
     */
    public static String formatInt(final int number) {
        String result = null;
        DecimalFormat df = new DecimalFormat(INTEGER_PATTERN);

        try {
            result = df.format(number);
        } catch (ArithmeticException ae) {
        }

        return result;
    }
}

Related

  1. formatFileLength(long length)
  2. formatGopNumber(Number gop)
  3. formatI18N(Object ob)
  4. formatiereSpeichergroesse(long bytes)
  5. formatIncludeCommas(final Number object)
  6. formatInteger(Object obj)
  7. formatIntoCurr(String str_number, int digits)
  8. formatLong(long value)
  9. formatNumber(final long number)